The website uses the Baidu map to realize the localization province (municipality) City (district)

Source: Internet
Author: User

<!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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.