1,通过百度地图api ip地址定位,取得市
function myFun(result){
var cityName = result.name;
map.setCenter(cityName);
alert("当前定位城市:"+cityName);
}
var myCity = new BMap.LocalCity();
myCity.get(myFun);
2.在市内搜索地址
var options = {
onSearchComplete: function(results){
console.dir(results);
// 判断状态是否正确
if (local.getStatus() == BMAP_STATUS_SUCCESS){
var s = [];
for (var i = 0; i < results.getCurrentNumPois(); i ++){
s.push(results.getPoi(i).title + ", " + results.getPoi(i).address);
}
document.getElementById("r-result").innerHTML = s.join("<br/>");
}
}
};
var local = new BMap.LocalSearch('苏州市', options);
local.search("千灯公园");
3.返回结果
返回搜索结果,包括省,市,地址,坐标