Copy code code as follows:
<! Doctype html>
<html>
<body>
<p ID = "Demo"> Click this button to get your position: </p>
<button OnClick = "GetLocation ()"> Try it </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 (if (navigator.Geolocation) {
navigator.Geology.getCurrentposition (Showposition);
} Else {
Alert ("Your browser does not support geographical positioning");
}
}
Function Showposition (Position) {
LAT = POSITION.COORDS.latitude;
lon = positive.coords.longitude;
// var map = new bmap.map ("container"); // Create a map instance
var point = new bmap.point (long, lat); // Create points 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>
</html>