<!doctype html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<meta name= "viewport" content= "initial-scale=1.0, User-scalable=no"/>
<script type= "Text/javascript" src= "Http://libs.baidu.com/jquery/1.7.2/jquery.min.js" ></script>
<script type= "Text/javascript" src= "http://api.map.baidu.com/api?v=2.0&ak= MNVBBwIzgeByQFMrcxMUXQIYSKHBWOY6 "> </script>
<title> Browser Location </title>
<body>
<div>
<span id= "Load_geolocation" > click Get Location </span>
</div>
</body>
<script type= "Text/javascript" >
$ (function () {
$ ("#load_geolocation"). Click (function (EV) {
$ (ev.currenttarget). Text ("Acquiring location ...");
Create a Baidu map control
var geolocation = new Bmap.geolocation ();
Geolocation.getcurrentposition (function (r) {
Console.log (R);
if (this.getstatus () = = bmap_status_success) {
Creates a coordinate point with the specified latitude and longitude
var pt = new Bmap.point (R.point.lng,r.point.lat);
Console.log (PT)
Create a geolocation resolver
var GEOC = new Bmap.geocoder ();
Geoc.getlocation (PT, function (RS) {//Parse format: City, county, street
var addcomp = rs.addresscomponents;
$ (ev.currenttarget). Text (addcomp.city + "," + Addcomp.district + "," + Addcomp.street);
});
}
else {
$ (ev.currenttarget). Text (' failed to locate ');
}
},{enablehighaccuracy:true})//instructs the browser to obtain a high-precision location, default false
});
});
</script>
The website uses the Baidu map to realize the localization province (municipality) City (district)