無 SSL 連線的 HTML5 地理位置


HTML 5 地理位置用於找出使用者的位置。這可以在沒有 SSL 連線的情況下完成。這可以透過如下方式生成 −

// Variable apigeo shows successful location:
var apigeo = function(position) {
   alert("API geolocation success!

lat = " + position.coords.latitude + "
lng = " + position.coords.longitude); }; var tryapigeo = function() {    jQuery.post( "check the location on google map", function(success) {       apiGeolocationSuccess({coords: {latitude: success.location.lat, longitude: success.location.lng}});    }) //Gives success on given geolocation    .failure(function(err) { //On failure, alert with failure is shown       alert("error while showing geolocation!

"+err);    }); };

然後,可以針對錯誤程式碼生成各種 switch case,不同的錯誤程式碼對應不同的錯誤。

var tryloc = function() {//tryloc variable show current position
if (navigator.geolocation) {
   navigator.geolocation.getCurrentPosition(
      browserGeolocationSuccess, browserGeolocationFail,{
      maximumAge: 70000, timeout: 40000, enableHighAccuracy: true});
   / /this will show result with high accuracy
}};

更新日期: 02-6-2020

645 次瀏覽

開啟你的 職業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.