1.只能精确到城市;
2.域名需要https;
html代码:
<script src="https://api.map.baidu.com/api?type=webgl&v=1.0&ak=key"></script>
<div id="container" style="width: 400px;height: 400px;"></div>
js代码:
<script> var map = new BMapGL.Map('container'); // 创建Map实例 var point = new BMapGL.Point(116.331398,39.897445); map.centerAndZoom(point,12); function myFun(result){ var cityName = result.name; map.setCenter(cityName); alert("当前定位城市:" + cityName); } var myCity = new BMapGL.LocalCity(); myCity.get(myFun); </script>