0

我正在使用 MapQuest 和 javascript 来反转地理编码纬度和经度坐标以验证城市名称。我将返回的结果与字符串“Los Angeles”进行比较。那是对的吗?我的代码如下

latitude = item.latitude;
longitude = item.longitude;


MQA.withModule('geocoder', function() {

/*Executes a geocode with an object containing lat/lng properties, adds result to the    map, and
adds a function to be called once geocoding is complete.*/
map.reverseGeocodeAndAddLocation(
 { lat: latitude, lng: longitude }, processRawData);

/*Example function used to show the address of the geocoded location*/
function processRawData(response) {



 if (response.results.length > 0 && response.results[0].locations.length > 0) {


       var location = response.results[0].locations[0];
       var town = location.adminArea5 + "";
}

if(town == "Los Angeles"){

    inLosAngeles += 1;
}

else {
    notLosAngeles +=1;
}

geoData += 'inLosAngeles=' + inLosAngeles + ',' + 'notLosAngeles' + notLosAngeles +      '</p>';

$('#results').append(geoData);


}

});
4

1 回答 1

0

如果您没有将结果放在地图上,您可以直接使用Geocode Web Service 反向地理编码器,只需将城市结果与“洛杉矶”进行比较。

http://www.mapquestapi.com/geocoding/v1/reverse?key=KEY&callback=compare&location=40.0755,-76.329999
于 2013-11-19T17:08:13.247 回答