首页 新闻 会员 周边 捐助

百度地图api

0
[已解决问题] 解决于 2013-01-22 20:34

我们现在用GPS可以获得两个地点的经纬度坐标,想问问百度地图的API有没有给两点坐标,按照地图来计算它们之间的距离。比如说给个天安门的坐标和王府井的坐标,计算两个位置的距离

GhostRider_zkc的主页 GhostRider_zkc | 初学一级 | 园豆:18
提问于:2013-01-21 13:30
< >
分享
最佳答案
0

<div id="map" style="height:600px; width:500px;">超级程序员酷云的杰作</div>
<script src="http://ditu.google.cn/maps?file=api&amp;v=2&amp;key=abcdefg&sensor=true_or_false" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
alert(document.getElementByIdx_x("map"));
var map = new GMap2(document.getElementByIdx_x("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(37.4419, -122.1419), 13);

// Create our "tiny" marker icon
var icon = new GIcon();
icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
icon.iconSize = new GSize(12, 20);
icon.shadowSize = new GSize(22, 20);
icon.iconAnchor = new GPoint(6, 20);
icon.infoWindowAnchor = new GPoint(5, 1);

// Add 10 markers to the map at random locations
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();
for (var i = 0; i < 10; i++) {
 

var point = new GLatLng(southWest.lat() + latSpan * Math.random(),
                          southWest.lng() + lngSpan * Math.random());
  map.addOverlay(new GMarker(point, icon));
}
//计算两点的距离
var distance = new GLatLng(39.917, 116.397).distanceFrom(new GLatLng(37.4419, -122.1419));  
 alert(parseInt(distance/1000,10) + "公里");
</script>

复制过来的,验证可以计算。建议用google地图,百度地图性能太差。我在地图上画2万个点,百度地图卡死了 谷歌依然坚挺

奖励园豆:5
truename | 初学一级 |园豆:168 | 2013-01-21 16:23
其他回答(1)
0

经纬度坐标可以转换为百度坐标,在haoservice网站上有,不让发链接 .

hhxq | 园豆:202 (菜鸟二级) | 2014-08-27 10:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册