【问题标题】:specify the name of country using longitude and latitude on android在android上使用经度和纬度指定国家名称
【发布时间】:2012-04-14 11:46:52
【问题描述】:

我在 android 模拟器上使用 google api 15。

我想通过触摸屏幕从地图上指定一个国家, 所以如果我在某个经度和纬度上触摸屏幕,我可以知道它们属于哪个国家或城市?

.. 非常感谢。

【问题讨论】:

  • 你有什么尝试吗?如果是这样,请分享您尝试过的代码或想法。如果你想依赖 google api,你需要反向地理编码并从结果中获取国家/地区部分。
  • 好的,我忘了包括我的尝试,谢谢你的注意,是的,我终于找到了一个解决方案,就像你说的反向地理编码:) :)。

标签: android google-maps google-maps-api-3


【解决方案1】:

你可以试试这样的:

public static String getCountryName(Context context, double latitude, double longitude) {
    Geocoder geocoder = new Geocoder(context, Locale.getDefault());
    List<Address> addresses = null;
    try {
        addresses = geocoder.getFromLocation(latitude, longitude, 1);
        Address result;

        if (addresses != null && !addresses.isEmpty()) {
            return addresses.get(0).getCountryName();
        }
        return null;
    } catch (IOException ignored) {
       //do something
    }

}

【讨论】:

  • @Cristian 我想知道你是否可以帮助我解决这个问题goo.gl/d5opg5。我保证,这不是那些“为我解决这个问题”的问题之一。
  • 这并不总是有效。它不适用于某些 Android 设备。不知道为什么 getFromLocation 不是一直在检索地址。
  • 你使用'result'的目的是什么??
猜你喜欢
  • 2012-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-24
  • 1970-01-01
  • 2020-04-16
  • 2012-05-22
  • 1970-01-01
相关资源
最近更新 更多