定位自己当前的位置,获取经纬度!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>  
    <meta charset="UTF-8"/>
    <title>点击地图获取地址和经纬度map,address,lng,lat</title>  
    <meta name="robots" content="noindex, nofollow">  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  
    <!-- 将百度地图API引入,设置好自己的key -->  
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=uRhBKfzW36pGW8KGkyAhpwXDYwmjNcZP"></script> 
</head>  
<body>  
  <div id="allmap"></div>
 
<script type="text/javascript">  
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(point,12);


var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
	if(this.getStatus() == BMAP_STATUS_SUCCESS){
		var mk = new BMap.Marker(r.point);
		map.addOverlay(mk);
		map.panTo(r.point);
		alert('您的位置:'+r.point.lng+','+r.point.lat);
	}
	else {
		alert('failed'+this.getStatus());
	}        
});
</script> 
</body>  
</html>

猜你喜欢

转载自blog.csdn.net/weixin_43764814/article/details/89476363
今日推荐