var MapLng;
var MapLat;
map.removeOverlay(marker);
geo.getPoint(obj.value, function (point) {
if (point) {
map.centerAndZoom(point, 15);
marker = new BMap.Marker(point);
map.addOverlay(marker);
MapLng = point.lng;
MapLat = point.lat;
}
}, '上海');
var ply = new BMap.Polygon(pts);
var pt = new BMap.Point(MapLng, MapLat);
geo.getLocation(pt, function (rs) {
var addComp = rs.addressComponents;
alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
});
沒有反應,各位求幫忙
解碼是異步的, geo.getPoint(obj.value, function (point) {這個回調還沒執行就已經執行 geo.getLocation(pt, function (rs) {這句了,導致pt變量沒有值。解碼要放到geo.getPoint(obj.value, function (point) {回調裡面
var MapLng;
var MapLat;
map.removeOverlay(marker);
geo.getPoint(obj.value, function (point) {
if (point) {
map.centerAndZoom(point, 15);
marker = new BMap.Marker(point);
map.addOverlay(marker);
MapLng = point.lng;
MapLat = point.lat;
pointToAddress(); ////////
}
}, '上海');
var ply = new BMap.Polygon(pts);
function pointToAddress() {
var pt = new BMap.Point(MapLng, MapLat);
geo.getLocation(pt, function (rs) {
var addComp = rs.addressComponents;
alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
});
}