Systems with Navigator.geolocation above IOS10 cannot be located

Source: Internet
Author: User

Yesterday the boss told me that the code has a bug (failed to locate), so the various tests finally found that the IOS10 version of the phone is not successful, first paste the failure code:

varCity =""; Navigator.geolocation.getCurrentPosition (function (position) {varLat =Position.coords.latitude; varLon =Position.coords.longitude; varPoint =NewBmap.point (lon, LAT);//Create a coordinate point//get address description based on coordinates                    varMygeo =NewBmap.geocoder (); Mygeo.getlocation (point, function (result) { City=result.addressComponents.city;                    alert (city);                }); });

After reviewing the data that iOS system in more than 10 version of the security issue to prohibit users in the HTTP protocol to locate, to locate the HTTP protocol must be upgraded to HTTPS protocol, of course, there are other ways, such as the call Baidu Map API interface implementation, nonsense, on the code:

<! DOCTYPE html>"UTF-8"> <script type="Text/javascript"Src="http://api.map.baidu.com/api?v=2.0&ak= your key (apply for free on Baidu maps)"></script> <title> positioning </title>"Allmap"style="width:0;height:0; display:none;"></div> <script type="Text/javascript">//Baidu Map API features    varMap =NewBmap.map ("Allmap"); varPoint =NewBmap.point (108.95,34.27); Map.centerandzoom (Point, A); varGeolocation =Newbmap.geolocation (); Geolocation.getcurrentposition (function (r) {console.log (r.point)if( This. getStatus () = =bmap_status_success) {            varmk =NewBmap.marker (R.point);            Map.addoverlay (MK);            Map.panto (R.point); varPoint =NewBmap.point (R.point.lng,r.point.lat); varGC =NewBmap.geocoder (); Gc.getlocation (Point, Function (RS) {varAddcomp =rs.addresscomponents;                   Console.log (RS); Alert (addcomp.city+"==="+addcomp.district)}); }Else{alert ('failed'+ This. GetStatus ()); }},{enablehighaccuracy:true})    </script> </body>

Use Baidu Map API interface to solve the problem perfectly.

Systems with Navigator.geolocation above IOS10 cannot be located

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.