2013-10-16 43 views
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); 


} 

}); 
+1

你是什麼意思「是正確的」?對於在洛杉磯的地點來說,它甚至可能是正確的。它工作嗎?你想做什麼?你有什麼問題? – geocodezip

+0

我在做一個學校項目,我正在驗證照片標籤'losangeles'是否真的在洛杉磯。我從Flickr照片中獲取經緯度,我從json電話網址獲得,然後我嘗試將地理編碼翻轉爲經緯度,以驗證它們是否在洛杉磯。我知道我的代碼無法正常工作,因爲一些標有'losangeles'的圖片在歐洲擁有很長的歷史。 –

+0

每個對flickr的json查詢都會爲每個頁面返回250個結果。我的計數總是返回所有250人都在洛杉磯,但情況並非如此。 –

回答

0

如果你不把結果在地圖上,你可以直接使用Geocode Web Service reverse geocoder,只是比較該市結果「洛杉磯」。

http://www.mapquestapi.com/geocoding/v1/reverse?key=KEY&callback=compare&location=40.0755,-76.329999 
相關問題