【问题标题】:How to get latitude and longitude from a given address in android? [duplicate]如何从android中的给定地址获取纬度和经度? [复制]
【发布时间】:2016-03-26 01:05:20
【问题描述】:

如何从android中的给定地址获取纬度和经度。

我想从地址中获取某个地方的纬度和经度。我不想从 GPS 或网络中获取纬度和经度。

【问题讨论】:

  • 请贴出您目前尝试过的代码。

标签: android latitude-longitude


【解决方案1】:

您可以使用以下方法:

// get latlng from address
    public LatLng getLocationFromAddress(String strAddress) {

        Geocoder coder = new Geocoder(context, Locale.getDefault());
        List<Address> address;
        LatLng p1 = null;

        try {
            address = coder.getFromLocationName(strAddress, 5);
            if (address == null) {
                return null;
            }
            Address location = address.get(0);
            location.getLatitude();
            location.getLongitude();

            p1 = new LatLng(location.getLatitude(), location.getLongitude());

            return p1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return p1;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    • 1970-01-01
    • 2013-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多