百度地图API:百度地图API
根据地址获取地址所在经纬度:
geocoder 中提供了getPoint() 方法获取
部分实现代码:
if(startAddress==""){
startAddress=$.location.current_location.address;
}
var map = new BMap.Map(container);
var geocoder = new BMap.Geocoder();
//默认为南京
var longitude = 118.807395;
var latitude = 32.065315;
//获取起始地址经纬度
geocoder.getPoint(startAddress,
function(point){
if(point)
{
longitude = point.lng;
latitude = point.lat;
}
},$.location.current_location.address);
//map.centerAndZoom(new BMap.Point(118.807395,32.065315), 14);
map.centerAndZoom(new BMap.Point(longitude,latitude), 14);
container为显示地图的一个容器,startAdress为起始位置
注:回调函数和主函数是异步执行的,如果在回调函数内对主函数中的一些变量进行操作,主函数的相关代码应放到回调函数中。
最终效果实现:
本文介绍了如何利用百度地图API的Geocoding API来获取指定地址的经纬度坐标。通过调用geocoder的getPoint()方法,可以异步获取到地理位置信息。示例代码展示了在特定容器中展示地图并获取起始位置经纬度的过程。

4588

被折叠的 条评论
为什么被折叠?



