One: Apply for Baidu AK Address: http://developer.baidu.com/map/index.php
Two: Code implementation
function GetLocation ()
{
if (navigator.geolocation)//judgment is or supports H5 positioning
{
Navigator.geolocation.getCurrentPosition (showposition);
}
Alert ("Failed to locate")
}
function showposition (position)
{
var x=position.coords.latitude,//transverse latitude and longitude
Y= Position.coords.longitude; Longitudinal latitude and longitude
$.ajax ({
URL: "Http://api.map.baidu.com/geocoder/v2/?ak=DiUvNUxnyXtEUz9a5wn3kXNy&callback=renderReverse&location = "+x+", "+y+" &output=json&pois=1 ",//This address is Baidu map inside an analytic http://developer.baidu.com/map/index.php?title= Webapi/guide/webservice-geocoding
Type: "GET",
DataType: "Jsonp",
Success:function (data) {
alert (data.result.addressComponent.city);
}
})
}
Mobile to locate the current city