HTML5 地理定位無 SSL 連線


HTML5 地理定位用於查詢使用者的地理位置。這是無需 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);    }); };

然後可生成錯誤程式碼的各種開關情況,不同的錯誤對應不同的錯誤程式碼。

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

648 次瀏覽

啟動你的職業生涯

透過完成課程獲得認證

開始
廣告