Question: 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?

Answer: 
Ud\_an's solution with updated API's 

**Note**: [LatLng](https://developers.google.com/android/reference/com/google/android/gms/maps/model/LatLng) class is part of Google Play Services.

**Mandatory**:

```
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<uses-permission android:name="android.permission.INTERNET"/>

```

**Update:** If you have target SDK 23 and above, make sure you take care of runtime permission for location.

```
public LatLng getLocationFromAddress(Context context,String strAddress) {

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

    try {
        // May throw an IOException
        address = coder.getFromLocationName(strAddress, 5);
        if (address == null) {
            return null;
        }

        Address location = address.get(0);
        p1 = new LatLng(location.getLatitude(), location.getLongitude() );

    } catch (IOException ex) {

        ex.printStackTrace();
    }

    return p1;
}

```
```
public LatLang getLatLangFromAddress(String strAddress){
    Geocoder coder = new Geocoder(this, Locale.getDefault());
    List<Address> 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.

`<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />` permission is not required.