根基百度api获取当前位置

首先引入百度api的

<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=你的ak"></script>

调用下面方法可以获取的位置信息

function geolocation() {
	var geolocation = new BMap.Geolocation();
	geolocation.getCurrentPosition(function(r) {
		if (this.getStatus() == BMAP_STATUS_SUCCESS) {
			var mk = new BMap.Marker(r.point);
			g_bmapx = r.point.lng;//精度
			g_bmapy = r.point.lat;//纬度
		} else {
		}
	}, {
		enableHighAccuracy : true
	})
}

猜你喜欢

转载自my.oschina.net/u/3500033/blog/1612968