调用高德地图搜索附近位置时,常常碰到这样的问题:amap.placesearch is not a constructor
原因是: new AMap.PlaceSearch 时外层没有引入红色的方法
AMap.service('AMap.PlaceSearch',function(){
});
function autoSearch(keywords) {
debugger
var auto;
var msearch;
var mapCenter = map.getCenter();
var lnglatXY = [mapCenter.getLng(), mapCenter.getLat()];
MGeocoder.getAddress(lnglatXY, function (status, result) {
if (status === 'complete' && result.info === 'OK') {
if (result.regeocode.pois.length > 0) {
var cityCode = result.regeocode.addressComponent.citycode;
AMap.service('AMap.PlaceSearch',function(){
msearch = new AMap.PlaceSearch({
pageSize:10,
pageIndex:1,
city:cityCode //城市
//panel: "_ListContainer"
});
});
if(keywords.length>0){
msearch.searchNearBy(keywords,lnglatXY, 100000, function(status, result1) {
autocomplete_CallBack(result1,cityCode);
});
}
}
}
});
}