2011-07-17 81 views
2

我想在我的android應用程序中使用API​​(首選爲Google地圖,如果支持的話)以傳遞位置的經度/緯度並且API返回城市名稱。傳遞lon/lat和返回城市名稱的API

在解決這個,你應該去getAddressLine(x)的

回答

2

我相信API是速率的限制。即在一個小時內您不能多次訪問該API。Android包含一個Geocoder類,它也具有ReverseGeocoding功能。請看this link

+0

謝謝,我認爲這是我需要的。我現在要測試它。 – mohamede1945

+0

我測試過了,但我無法使用它來獲取城市。你知道一個辦法嗎? – mohamede1945

+0

您需要在清單中擁有互聯網許可。 Geocoder geocoder = new Geocoder(this,Locale.getDefault()); 列表

addresses = geocoder.getFromLocation(lat,lng,1); addresses.get(0).getLocality();'地點應該給你這座城市。 – Varun

1

請求什麼Geonames.org是另一回事。下面是一個示例API調用來找到西雅圖附近的名字: http://api.geonames.org/citiesJSON?north=47.65&south=47.55&east=-122.30&west=-122.40&lang=de&username=demo

{ 
    "geonames": [ 
     { 
      "fcodeName": "seat of a second-order administrative division", 
      "countrycode": "US", 
      "fcl": "P", 
      "fclName": "city, village,...", 
      "name": "Seattle", 
      "wikipedia": "", 
      "lng": -122.3320708, 
      "fcode": "PPLA2", 
      "geonameId": 5809844, 
      "lat": 47.6062095, 
      "population": 608660 
     }, 
     { 
      "fcodeName": "populated place", 
      "countrycode": "US", 
      "fcl": "P", 
      "fclName": "city, village,...", 
      "name": "Yesler Terrace", 
      "wikipedia": "", 
      "lng": -122.3159591, 
      "fcode": "PPL", 
      "geonameId": 5816674, 
      "lat": 47.6009318, 
      "population": 0 
     }, 
     { 
      "fcodeName": "section of populated place", 
      "countrycode": "US", 
      "fcl": "P", 
      "fclName": "city, village,...", 
      "name": "North Broadway", 
      "wikipedia": "", 
      "lng": -122.3204044, 
      "fcode": "PPLX", 
      "geonameId": 5804929, 
      "lat": 47.6462094, 
      "population": 0 
     }, 
     { 
      "fcodeName": "populated place", 
      "countrycode": "US", 
      "fcl": "P", 
      "fclName": "city, village,...", 
      "name": "Capitol Hill", 
      "wikipedia": "", 
      "lng": -122.3195706, 
      "fcode": "PPL", 
      "geonameId": 5789123, 
      "lat": 47.6234317, 
      "population": 0 
     }, 
     { 
      "fcodeName": "populated place", 
      "countrycode": "US", 
      "fcl": "P", 
      "fclName": "city, village,...", 
      "name": "Interbay", 
      "wikipedia": "", 
      "lng": -122.3959623, 
      "fcode": "PPL", 
      "geonameId": 5798384, 
      "lat": 47.641209, 
      "population": 0 
     }, 
     { 
      "fcodeName": "populated place", 
      "countrycode": "US", 
      "fcl": "P", 
      "fclName": "city, village,...", 
      "name": "Ross (historical)", 
      "wikipedia": "", 
      "lng": -122.3623502, 
      "fcode": "PPL", 
      "geonameId": 5808844, 
      "lat": 47.6478758, 
      "population": 0 
     }, 
     { 
      "fcodeName": "populated place", 
      "countrycode": "US", 
      "fcl": "P", 
      "fclName": "city, village,...", 
      "name": "Stevens", 
      "wikipedia": "", 
      "lng": -122.3066667, 
      "fcode": "PPL", 
      "geonameId": 7153940, 
      "lat": 47.6297222, 
      "population": 0 
     }, 
     { 
      "fcodeName": "section of populated place", 
      "countrycode": "US", 
      "fcl": "P", 
      "fclName": "city, village,...", 
      "name": "Belltown", 
      "wikipedia": "", 
      "lng": -122.3509605, 
      "fcode": "PPLX", 
      "geonameId": 5786913, 
      "lat": 47.6164871, 
      "population": 0 
     }, 
     { 
      "fcodeName": "populated place", 
      "countrycode": "US", 
      "fcl": "P", 
      "fclName": "city, village,...", 
      "name": "Queen Anne", 
      "wikipedia": "", 
      "lng": -122.366239, 
      "fcode": "PPL", 
      "geonameId": 5807648, 
      "lat": 47.6359314, 
      "population": 0 
     }, 
     { 
      "fcodeName": "populated place", 
      "countrycode": "US", 
      "fcl": "P", 
      "fclName": "city, village,...", 
      "name": "South Seattle", 
      "wikipedia": "", 
      "lng": -122.312903, 
      "fcode": "PPL", 
      "geonameId": 5811509, 
      "lat": 47.5614876, 
      "population": 0 
     } 
    ] 
} 
相關問題