<!DOCTYPE html>
<html>
<head>
<meta charset=
"UTF-8"
>
<script type=
"text/javascript"
src=
"
</script>
<title>百度地图的定位</title>
</head>
<body>
<p id="
allmap
" style="
width: 100%;height: 500px;
"></p>
<script type="
text/javascript
">
// 百度地图API功能
var map = new BMap.Map("
allmap");
var
point =
new
BMap.Point(108.95,34.27);
map.centerAndZoom(point,12);
var
geolocation =
new
BMap.Geolocation();
geolocation.getCurrentPosition(
function
(r){console.log(r.point)
if
(
this
.getStatus() == BMAP_STATUS_SUCCESS){
var
mk =
new
BMap.Marker(r.point);
map.addOverlay(mk);
map.panTo(r.point);
var
point =
new
BMap.Point(r.point.lng,r.point.lat);
var
gc =
new
BMap.Geocoder();
gc.getLocation(point,
function
(rs){
var
addComp = rs.addressComponents; console.log(rs.address);
alert(rs.address);
});
}
else
{
alert(
'failed'
+
this
.getStatus());
}
},{enableHighAccuracy:
true
})</script></body></html>