【发布时间】:2011-07-17 00:57:33
【问题描述】:
我想在我的 android 应用程序中使用 API(如果支持的话,最好是谷歌地图)来传递位置的经度/纬度,并且 API 返回城市名称。
在解决这个问题时,您应该使用 getAddressLine(x)
【问题讨论】:
标签: android api latitude-longitude city
我想在我的 android 应用程序中使用 API(如果支持的话,最好是谷歌地图)来传递位置的经度/纬度,并且 API 返回城市名称。
在解决这个问题时,您应该使用 getAddressLine(x)
【问题讨论】:
标签: android api latitude-longitude city
我认为 API 是有速率限制的。即你不能在一个小时内多次访问 API。Android 包含一个 Geocoder 类,它也执行 ReverseGeocoding。看看this link。
【讨论】:
Geocoder geocoder = new Geocoder(this, Locale.getDefault()); List<Address> addresses = geocoder.getFromLocation(lat, lng, 1); addresses.get(0).getLocality(); Locality 应该给你城市。
我相信 google 确实提供了您在此处所要求的内容 http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding
【讨论】:
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
}
]
}
【讨论】: