1

How to get latitude and longitude from a given address in android.

I want to get the latitude and longitude of a place from an address. I don't want to get the latitude and longitude from the GPS nor the the network.

curiousMind
  • 2,812
  • 1
  • 17
  • 38
ACP Daya
  • 71
  • 1
  • 5

1 Answers1

0

You can use below method:

// 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;
    }
Pankaj
  • 7,908
  • 6
  • 42
  • 65