2011-06-06 99 views
1

可能重複:
how i can get latitude , longitude of a location programmatically or using a api獲得一個位置的緯度和經度

我使用>http://www.weather.gov/forecasts/xml/SOAP_server/ndfdXML.htm。獲取地點的天氣情況。在這裏,我需要將緯度和經度傳遞給web方法。我有位置名稱,但不包括緯度&經度值。所以我想獲取這兩個位置的值。有什麼辦法可以得到它。

+0

您能舉一個您正在使用的地點名稱的示例嗎? – takrl 2011-06-06 10:46:18

+0

芝加哥伊利諾伊州。 – 2011-06-06 10:52:49

+0

在這種情況下,[this](http://stackoverflow.com/questions/3490622/get-latitude-and-longitude-based-on-location-name-google-maps-api)或[this](http: //stackoverflow.com/questions/3246553/googles-geocode-convert-city-state-into-latitude-longitude)可能會有所幫助。 – takrl 2011-06-06 11:04:33

回答

2

既然您用Google標記了該問題,我認爲您想使用Google Geocoding API service?這裏的文檔解釋瞭如何使用它 - 將地址作爲查詢字符串參數傳遞給服務(通過簡單的REST,如URL),您可以獲取XML或JSON。 XML查詢的一個例子:

http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false

由於XML響應的一部分,你會看到經/緯:

<location> 
    <lat> 
    37.4213068 
    </lat> 
    <lng> 
    -122.0852900 
    </lng> 
</location> 

只記得到sensor參數設置爲truefalse作爲這是必需的。

注意第3版API不需要API密鑰,但確實有一些usage limitations你應該知道的,包括:

  • 每天2500所地理位置查詢請求的限制。
  • 地理編碼API只能與Google地圖一起使用;禁止在地圖上顯示地理編碼結果