实现代码
第一步:获取经纬度
第二步:根据经纬度调用百度获取地址
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style type="text/css">
html {
height: 100%
}
body {
height: 100%;
margin: 0px;
padding: 0px
}
#container {
height: 100%;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=你的百度ak"></script>
<script>
var map = new BMapGL.Map("container");
var point = new BMapGL.Point(116.404, 39.915);
map.centerAndZoom(point, 15);
var geolocation = new BMapGL.Geolocation();
geolocation.enableSDKLocation();
geolocation.getCurrentPosition(function (r) {
if (this.getStatus() == BMAP_STATUS_SUCCESS) {
var mk = new BMapGL.Marker(r.point);
map.addOverlay(mk);
map.panTo(r.point);
alert('您的位置:' + r.point.lng + ',' + r.point.lat);
// 创建地理编码实例
var myGeo = new BMapGL.Geocoder();
// 根据坐标得到地址描述
myGeo.getLocation(new BMapGL.Point(r.point.lng, r.point.lat), function (result) {
if (result) {
alert(result.address);
}
});
}
else {
alert('failed' + this.getStatus());
}
});
</script>
</body>
</html>
参考
正逆地址解析:https://lbsyun.baidu.com/index.php?title=jspopularGL/guide/geocoding
定位:https://lbsyun.baidu.com/index.php?title=jspopularGL/guide/geoloaction

