我正在使用MapQuest和javascript来反转地理编码纬度和经度坐标来验证城市名称。我将返回的结果与字符串“洛杉矶”进行比较。那是对的吗?我的代码在
之下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);
}
});
答案 0 :(得分:0)
如果您没有将结果放在地图上,可以直接使用Geocode Web Service reverse geocoder,只需将城市结果与“洛杉矶”进行比较。
http://www.mapquestapi.com/geocoding/v1/reverse?key=KEY&callback=compare&location=40.0755,-76.329999