// 百度地图API功能
var mp = new BMap.Map(‘map‘);
mp.centerAndZoom(new BMap.Point(108.953451, 34.265773), 15);
mp.addControl(new BMap.ScaleControl());
mp.addControl(new BMap.OverviewMapControl());
mp.enableScrollWheelZoom();
var geo = new BMap.Geocoder();
$("#text").val("");
$("#s_btn").click(function(){
var s_text = $("#text").val();
$("#res").show();
geo.getPoint(s_text, function(point){
if(point)
{
alert(point.lng + ":" + point.lat);
mp.centerAndZoom(point, 16);
mp.addOverlay(new BMap.Marker(point));
}
}, "西安市");
});
getPoint是百度地图API,参数为目标字符串,回调函数,城市
目标点的百度地理坐标其实就是point.lng和point.lat(刚开始以为是x和y了,结果好一阵纠结)
时间: 2024-10-05 23:54:06