Perfect solution Window.navigator.geolocation.getCurrentPosition, unable to locate the problem in the IOS10 system

Source: Internet
Author: User

Now that many users have upgraded their phones to iOS, Apple's iOS 10 has been officially pushed out, and many users have been updated to the latest system. However, if the Web site does not support the HTTPS protocol in a timely manner, when many users have access to many websites under iOS 10, they will not be able to accurately locate the normal, resulting in some of the site's surrounding referral service does not work properly. Why can't I get the current location information under iOS 10? This is because in iOS 10, Apple has modified the WebKit location permission, and all of the location request pages must be HTTPS protocol. If a non-HTTPS Web page, the HTTP protocol through the HTML5 native location interface will return an error, that is, unable to properly navigate to the user's specific location, and the Web site that has supported HTTPS will not be affected.

The solutions currently available:

1. Set HTTP for the website to HTTPS.

2, through the third-party solution, this is my current method of use.

First look at the code differences:

1, the introduction of JS on the page

<script src= "/content/scripts/jquery.flexslider.js" ></script>  <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>  

Window.navigator.geolocation.getCurrentPosition: WebKit location via mobile phone (currently not supported on non-HTTPS sites for iOS systems)

Navigator.geolocation.getCurrentPosition (Translatepoint);//positioningfunctionTranslatepoint (position) {varCurrentlat =Position.coords.latitude; varCurrentlon =Position.coords.longitude; Setcookie ("Curlat", Currentlat, 1);//Set CookiesSetcookie ("Curlng", Currentlon, 1);//Set Cookies      varGpspoint =NewBmap.point (Currentlon, Currentlat);
varPT =NewBmap.point (Currentlon, Currentlat); varGEOC =NewBmap.geocoder (); Geoc.getlocation (PT,function(RS) {varAddcomp =rs.addresscomponents; Setcookie ("Curlat", Currentlat, 1);//Set CookiesSetcookie ("Curlng", Currentlon, 1);//Set Cookies        //alert (json.stringify (Addcomp));        varCity = addcomp.city;//Get specific Street information        varTexts = addcomp.district + "-" + Addcomp.street + "-" +Addcomp.streetnumber; $("#nowRoad"). Text (texts); });
}

Site does not support HTTPS access

1, Page introduced JS

<script src= "/content/scripts/jquery.flexslider.js" ></script>  <script type= "Text/javascript" Src= "Http://api.map.baidu.com/api?v=2.0&ak=6yAoynmTPNlTBa8z1X4LfwGE" ></script>  
varGeolocation =Newbmap.geolocation (); Geolocation.getcurrentposition (function(r) {if( This. getStatus () = =bmap_status_success) {varmk =NewBmap.marker (R.point); Currentlat=R.point.lat; Currentlon=r.point.lng; Setcookie ("Curlat", Currentlat, 1);//Set CookiesSetcookie ("Curlng", Currentlon, 1);//Set Cookies        varPT =NewBmap.point (Currentlon, Currentlat); varGEOC =NewBmap.geocoder (); Geoc.getlocation (PT,function(RS) {varAddcomp =rs.addresscomponents; Setcookie ("Curlat", Currentlat, 1);//Set CookiesSetcookie ("Curlng", Currentlon, 1);//Set Cookies                          varCity =addcomp.city; varAddcomp =rs.addresscomponents; varTexts = addcomp.district + "-" + Addcomp.street + "-" +Addcomp.streetnumber; //get location success, jump

}

The current method of acquiring positioning is here, only for your reference use!

Perfect solution Window.navigator.geolocation.getCurrentPosition, unable to locate the problem in the IOS10 system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.