使用百度api 解析地址的经纬度,可实现当前位置到该地址的
使用百度api 解析地址的经纬度,可实现当前位置到该地址的距离
// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
// 创建地址解析器实例
var myGeo = new BMap.Geocoder();
// 将地址解析结果显示在地图上,并调整地图视野
myGeo.getPoint("{$shop.address}", function(point){
if (point) {
var dstLng=(point['lng']);//x
var dstLat=(point['lat']);//y
var myLocation = new BMap.Geolocation();
myLocation.getCurrentPosition(function(r){
if(this.getStatus() == BMAP_STATUS_SUCCESS){
//元素
var numId='juli-'+{$smarty.foreach.shop.iteration};
var pointA = new BMap.Point(dstLng,dstLat); // 创建点坐标A
var pointB = new BMap.Point(r.point.lng,r.point.lat); // 创建点坐标B
document.getElementById(numId).innerHTML=((map.getDistance(pointA,pointB))/1000).toFixed(2);
}
else {
alert('failed'+this.getStatus());
}
},{enableHighAccuracy: true})
}else{
alert("您选择地址没有解析到结果!");
}
}, "北京市"); Dcr163的博客
http://dcr163.cn/89.html(转载时请注明本文出处及文章链接)
