IOS10 window.navigator.geolocation.getCurrentPosition 無法定位問題

來源:互聯網
上載者:User

標籤:containe   time   geo   nav   頁面   知識庫   擷取   ios10   reg   

在iOS 10中,蘋果對webkit定位許可權進行了修改,所有定位請求的頁面必須是https協議的。

如果是非https網頁,在http協議下通過HTML5原生定位介面會返回錯誤,也就是無法正常定位到使用者的具體位置,而已經支援https的網站則不會受影響。

目前提供的解決方案:

  1、將網站的http設定為Https。

  2、通過第三方API解決。

順便附上定位方法:

    // //定位方法一
$(function(){
startgps();
});
//擷取地理位置方法
function startgps()
{
//判斷是否支援
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showgps,//成功回呼函數
function(error) //失敗回呼函數
{
getPositionError(error);
},
{enableHighAcuracy: true, timeout:5000,maximumAge: 0}); // 這裡設定逾時為5000毫秒,即1秒
}
else
{
document.getElementById(‘geo_loc‘).innerHTML="您的瀏覽器不支援地圖定位";

}
}
function showgps(position)
{
document.getElementById(‘longitude‘).innerHTML="經度"+position.coords.longitude+ "緯度"+position.coords.latitude;
getAddress(position.coords.latitude,position.coords.longitude);

}
function getPositionError(error){
switch(error.code){

case error.TIMEOUT:

alert("連線逾時,請重試");

break;

case error.PERMISSION_DENIED:

alert("您拒絕了使用位置共用服務,查詢已取消");

break;

case error.POSITION_UNAVAILABLE:

alert("親愛的火星網友,非常抱歉,我們暫時無法為您所在的星球提供位置服務");

break;

}
}



//定位方法二
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(
function(position){
document.getElementById(‘longitude‘).innerHTML="經度"+position.coords.longitude+ "緯度"+position.coords.latitude;
document.getElementById(‘accuracy‘).innerHTML="誤差"+position.coords.accuracy+"米";
getAddress(position.coords.latitude,position.coords.longitude);
},
function(error){
var errorType = [‘您拒絕共用位置資訊‘, ‘擷取不到位置資訊‘, ‘擷取位置資訊逾時‘];
// alert(errorType[error.code - 1]);
document.getElementById(‘geo_loc‘).innerHTML=error.code+"\n"+error.message;
document.getElementById(‘geo_loc‘).innerHTML= errorType[error.code - 1];
}
);
}else{
document.getElementById(‘geo_loc‘).innerHTML="您的瀏覽器不支援地圖定位";
}

function getAddress(latitude,longitude){
var geocoder;
var map = new AMap.Map("container", {
resizeEnable: true,
zoom: 18
})
var lnglatXY = [longitude,latitude];//需轉為地址描述的座標
//載入地理編碼外掛程式
var geocoder;
AMap.service(["AMap.Geocoder"], function() {
geocoder = new AMap.Geocoder({
radius: 1000,
extensions: "all"
});
//逆地理編碼
geocoder.getAddress(lnglatXY, function(status, result){
//取回逆地理編碼結果
if(status === ‘complete‘ && result.info === ‘OK‘){
geocoder_CallBack(result);
}
});
});
}
function geocoder_CallBack(data) {
var address = data.regeocode.formattedAddress; //返回地址描述
document.getElementById("result").innerHTML = address;
}

 

IOS10 window.navigator.geolocation.getCurrentPosition 無法定位問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.