android - 我如何使用 GPS 在 android 中找到地点或建筑物名称而不是地址?

标签 android gps android-location android-gps

我想要实际的地点或建筑物名称,而不是使用 GPS 的 andoird 应用程序中的地址。

例如:如果我在购物中心,我的应用程序应该显示我在 XXXX 购物中心。

目前我正在使用纬度和经度获取地址。

如果遵循这个http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/

最佳答案

通过使用 Google Geocoder你将能够实现你所寻求的。它返回 Address包含有关您传递给它的 latitudelongitude 位置的所有信息的对象。下面是如何使用它的示例:

    if (Geocoder.isPresent()) {
        Geocoder gc = new Geocoder(context);
        List<Address> addresses = gc.getFromLocation(latitude, longitude, 1);
        // do stuff with addresses
    }

如果它无法返回一个好的 Address 对象,您仍然可以尝试使用 url 方法:

    URL url = new URL("http://maps.googleapis.com/maps/api/geocode/json?latlng=" + String.valueOf(latitude) + "," + String.valueOf(longitude) + "&sensor=false&language=" + Locale.getDefault().getLanguage());
    HttpURLConnection connection = (HttpURLConnection)url.openConnection();

    InputStream in = connection.getInputStream();
    JSONObject responseData;
    try {
        Scanner s = new Scanner(in).useDelimiter("\\A");
        try {
            String text = s.next();
            responseData = new JSONObject(text);
        } finally {
            s.close();
        }
    } finally {
        in.close();
    }

    // Do stuff with responseData, all the usefull informations are in this payload

关于android - 我如何使用 GPS 在 android 中找到地点或建筑物名称而不是地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35450282/

相关文章:

android - 电话间隙 : how to check if gps is enabled

ios - 如何在 ios 中更改消息 'Allow "App“以访问您的位置”

Android:如何在不注册谷歌帐户的情况下获取网络坐标

android - 处理 - 错误

java - '创建新的 Android 虚拟设备 (AVD )' hangs after I click ' ok'

android - 日志猫连续运行

java - 简化/缩短 TextView 分配

android - 致命异常 : main java. lang.StackOverflowError

android - Geocoder.getFromLocation grpc 在 Android 真机上失败

android - 我什么时候应该使用 ACCESS_COARSE_LOCATION 权限?