0
我使用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);
}
});
你是什麼意思「是正確的」?對於在洛杉磯的地點來說,它甚至可能是正確的。它工作嗎?你想做什麼?你有什麼問題? – geocodezip
我在做一個學校項目,我正在驗證照片標籤'losangeles'是否真的在洛杉磯。我從Flickr照片中獲取經緯度,我從json電話網址獲得,然後我嘗試將地理編碼翻轉爲經緯度,以驗證它們是否在洛杉磯。我知道我的代碼無法正常工作,因爲一些標有'losangeles'的圖片在歐洲擁有很長的歷史。 –
每個對flickr的json查詢都會爲每個頁面返回250個結果。我的計數總是返回所有250人都在洛杉磯,但情況並非如此。 –