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