Previously in the micro-letter enterprise development: Micro-letter attendance in the use of Baidu map positioning components, but found in some mobile phones will appear positioning failure tips, so there is a study of Baidu map. The original use of the Web Components Baidu is not going to update, but also to check the other Baidu map of the API, there is a JavaScript API popular version, and then tried, did not expect to solve the problem.
The core code is simple:
<div id= "Allmap" ></div>
<script type= "Text/javascript" src= "http://api.map.baidu.com/api?v=2.0" &ak=kkkk "></script>
<script type=" Text/javascript ">
//Baidu Map API function
var map = new Bmap.map ("Allmap");
var circle = new Bmap.geolocation ();
Circle.getcurrentposition (Locationresult);
Map.addoverlay (circle);
function Locationresult (geolocationresult) {
var status = This.getstatus ()
if (Status = 0)//retrieve succeeded. Corresponds to the value "0".
{
$ ("#lng"). Val (geolocationResult.point.lng);
$ ("#lat"). Val (GeolocationResult.point.lat);
var address = geolocationresult.address;
$ ("#city"). Val (address.city);
$ ("#district"). Val (address.district);
$ ("#street"). Val (address.street);
$ ("#address"). Val (address.province + address.city + address.district + address.street + address.street_number);
}
else {
alert ("Locate failure error code" + Status)
}
}
</script>
Implementation effect
The above content to share the micro-credit enterprise public number of the development of micro-letter attendance Baidu map positioning, code easy to understand, need friends to learn it quickly.