日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

ios10不能定位 window.navigator.geolocation.getCurrentPosition(定位第一节)

發布時間:2025/3/11 windows 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ios10不能定位 window.navigator.geolocation.getCurrentPosition(定位第一节) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原文連接:

https://blog.csdn.net/michael_ouyang/article/details/54137709

---------------------------------------------------------?

問題分析:

目前由于許多蘋果用戶都升級到了iOS系統,蘋果的iOS 10已經正式對外推送,相信很多用戶已經更新到了最新的系統。然而,如果web站沒有及時支持https協議的話,當很多用戶在iOS 10下訪問很多網站時,會發現都無法進行正常精確定位,導致部分網站的周邊推薦服務無法正常使用。為何在iOS 10下無法獲取當前位置信息?這是因為在iOS 10中,蘋果對webkit定位權限進行了修改,所有定位請求的頁面必須是https協議的。如果是非https網頁,在http協議下通過html5原生定位接口會返回錯誤,也就是無法正常定位到用戶的具體位置,而已經支持https的網站則不會受影響。

?

? ?目前提供的解決方案:

? 1、將網站的http設置為Https。

? 2、通過第三方解決,這也是我目前使用的方法。

?

?

? ?首先看以下兩段代碼:


代碼段一:

? ? ? ? ??1、在頁面引入js

?

  • <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=6yAoynmTPNlTBa8z1X4LfwGE"></script>

  • <script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>

  • ?

    ?

    ? ? ? ? ?2、獲得定位方法??window.navigator.geolocation.getCurrentPosition:通過手機的webKit定位(目前ios系統對非https網站不提供支持)

    ?

  • navigator.geolocation.getCurrentPosition(translatePoint); //定位

  • function translatePoint(position) {

  • var currentLat = position.coords.latitude;

  • var currentLon = position.coords.longitude;

  • SetCookie("curLat", currentLat, 1);//設置cookie

  • SetCookie("curLng", currentLon, 1);//設置cookie

  • var gpsPoint = new BMap.Point(currentLon, currentLat);

  • ?
  • var pt = new BMap.Point(currentLon, currentLat);

  • var geoc = new BMap.Geocoder();

  • geoc.getLocation(pt, function (rs) {

  • var addComp = rs.addressComponents;

  • SetCookie("curLat", currentLat, 1); //設置cookie

  • SetCookie("curLng", currentLon, 1); //設置cookie

  • //alert(JSON.stringify(addComp));

  • var city = addComp.city;

  • //獲得具體街道信息

  • var texts = addComp.district + "-" + addComp.street + "-" + addComp.streetNumber;

  • $("#nowRoad").text(texts);

  • });

  • }


  • ?

    ?

    代碼段二:

    ? ? ? ? ??1、在頁面引入js

    ?

  • <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=6yAoynmTPNlTBa8z1X4LfwGE"></script>

  • <script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>

  • ?

    ?

    ? ? ? ? ? ?2、獲得定位方法

    ?

  • var geolocation = new BMap.Geolocation();

  • geolocation.getCurrentPosition(function (r) {

  • if (this.getStatus() == BMAP_STATUS_SUCCESS) {

  • var mk = new BMap.Marker(r.point);

  • currentLat = r.point.lat;

  • currentLon = r.point.lng;

  • SetCookie("curLat", currentLat, 1); //設置cookie

  • SetCookie("curLng", currentLon, 1); //設置cookie

  • var pt = new BMap.Point(currentLon, currentLat);

  • var geoc = new BMap.Geocoder();

  • geoc.getLocation(pt, function (rs) {

  • var addComp = rs.addressComponents;

  • SetCookie("curLat", currentLat, 1); //設置cookie

  • SetCookie("curLng", currentLon, 1); //設置cookie

  • ?
  • var city = addComp.city;

  • var addComp = rs.addressComponents;

  • var texts = addComp.district + "-" + addComp.street + "-" + addComp.streetNumber;

  • //獲取地理位置成功,跳轉

  • ?
  • });

  • }

  • });

  • ?

    以上兩端代碼中,最大的不同點在于:

    第一段代碼使用的是

    window.navigator.geolocation.getCurrentPosition()

    此方法是通過UIwebview的內核webKit進行定位

    ?

    第二段代碼使用的是

    var geolocation = new BMap.Geolocation(); ?
    geolocation.getCurrentPosition()

    此方式是使用了百度api

    附相關連接:http://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference.html

    ?

    ?

    另外,值得注意的一個問題是:

    使用window.navigator.geolocation.getCurrentPosition()?獲取到的一個經緯度,還不能直接使用,還需要經過解密,才能獲取到準備的地理位置

    想知道如何把這個位置進行解密轉換,請留意下一遍文章

    http://blog.csdn.net/michael_ouyang/article/details/54378338

    ?

    原文鏈接:http://blog.csdn.net/for12/article/details/52803787

    總結

    以上是生活随笔為你收集整理的ios10不能定位 window.navigator.geolocation.getCurrentPosition(定位第一节)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。