Copy Code code as follows:
<! DOCTYPE html>
<body>
<p id= "Demo" > Click this button to get your location:</p>
<button onclick= "getLocation ()" > Try </button>
<script src= "http://api.map.baidu.com/api?v=1.4" type= "Text/javascript" ></script>
<script>
var X=document.getelementbyid ("demo");
function GetLocation () {
if (navigator.geolocation) {
Navigator.geolocation.getCurrentPosition (showposition);
}else{
Alert ("Your browser does not support geo-positioning");
}
}
function Showposition (position) {
Lat=position.coords.latitude;
Lon=position.coords.longitude;
var map = new Bmap.map ("container"); Create a Map instance
var point = new Bmap.point (lon, LAT); Create point coordinates
Map.centerandzoom (point,15); //
Map.enablescrollwheelzoom ();
var gc = new Bmap.geocoder ();
Gc.getlocation (Point, Function (RS) {
var addcomp = rs.addresscomponents;
Alert (addcomp.province + "," + addcomp.city + "," + Addcomp.district + "," + Addcomp.street);
});
}
</script>
</body>