【发布时间】:2015-09-04 21:23:13
【问题描述】:
我在我的应用程序中使用谷歌反向地理编码 API,我成功地能够使用谷歌地理定位 API 获取坐标。现在我正在尝试从反向地理编码 API 获取位置名称,但总是返回 Location not found 错误
这是我的代码:
Geocoder geocoder= new Geocoder(MainActivity.this, Locale.ENGLISH);
if(geocoder.isPresent()){
List<Address> list;
try {
list = geocoder.getFromLocation(37.42279, -122.08506,1);
Address address = list.get(0);
Log.d("this is working","thsi sis working");
StringBuffer str = new StringBuffer();
str.append("Name: " + address.getLocality() + "\n");
str.append("Sub-Admin Ares: " + address.getSubAdminArea() + "\n");
str.append("Admin Area: " + address.getAdminArea() + "\n");
str.append("Country: " + address.getCountryName() + "\n");
str.append("Country Code: " + address.getCountryCode() + "\n");;
String strAddress = str.toString();
JsonDatas.setText(strAddress);
Log.d("Address", strAddress);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我有几个问题
- google 如何知道哪个应用程序请求了 API,以及 google 如何确定该应用程序的配额。在 google API 开发者控制台中,google 为应用 API 提供了配额
- 为什么我得到位置未找到错误,但在谷歌地图位置上搜索却显示
- 我是否需要将 google Geocoder APi 密钥添加到我的应用程序中 - 现在我只有 Geolocation API 密钥用于检索坐标
如果我错了,请纠正我,请提出建议,以便我的代码可以正常工作
谢谢
【问题讨论】:
-
1.取决于 api,但每个请求都会花费配额。通常,您需要一个密钥才能访问 api,以便跟踪和识别您的使用情况。其他时候,它可能是通过您的 IP。 2. 只是一个特定的请求还是所有的请求? 3. Android Geocoder 无需 api 密钥即可使用。
-
感谢您的信息,我得到每个坐标的位置未找到错误,我正在使用 Geocoder api,我无法从坐标中获取位置,你能分享任何有反向的好链接吗api 或 google map v3 api android 示例@Andy
标签: android api google-maps google-maps-api-3 reverse-geocoding