1, load Baidu API Core Js,ak said to get Baidu map development key, free to apply for the next
<script type= "Text/javascript" src= "http://api.map.baidu.com/api?v=2.0&ak= 42b8ececa9cd6fe72ae4cddd77c0da5d "></script>
2. Code:
Set default geo-location access failed when using default geolocation
var defaultposition= "121.48479060028a31.234309729773";
1 if($.cookie ("apppoi") = =NULL|| $.cookie ("apppoi") = = "Undefined" | | $.cookie ("apppoi") = =undefined) {2 varGeolocation =Newbmap.geolocation ();3Geolocation.getcurrentposition (function(r) {4 if(R.point! =undefined) {5$LNG =r.point.lng;6$lat =R.point.lat;7 }8 if(R.longitude! =undefined) {9$LNG =R.longitude;Ten$lat =R.latitude; One } A if($LNG! = 0){ -$.cookie ("Apppoi", $lng + "a" + $lat, {expires:1}); - } the if( This. getStatus () = =bmap_status_success) { -Apppoi = $lng + "a" +$lat; -}Else { -Apppoi =defaultposition; + } - +},{enablehighaccuracy:true, Atimeout:3000, atMaximumage:5000*60}); -}Else{ -Apppoi = $.cookie ("Apppoi"); -}
Receive the latitude and longitude descendants in the background ' a ' is separated by the delimiter and address resolution (see Tool class for parsing methods)
JS get geographical latitude and longitude