How can I find the latitude and longitude from address?

前端 未结 9 1186
礼貌的吻别
礼貌的吻别 2020-11-22 10:27

I want to show the location of an address in Google Maps.

How do I get the latitude and longitude of an address using the Google Maps API?

9条回答
  •  生来不讨喜
    2020-11-22 11:03

    public LatLang getLatLangFromAddress(String strAddress){
        Geocoder coder = new Geocoder(this, Locale.getDefault());
        List
    address; try { address = coder.getFromLocationName(strAddress,5); if (address == null) { return new LatLang(-10000, -10000); } Address location = address.get(0); return new LatLang(location.getLatitude(), location.getLongitude()); } catch (IOException e) { return new LatLang(-10000, -10000); } }

    LatLang is a pojo class in this case.

    permission is not required.

提交回复
热议问题