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: 
```
 yourButton.setOnClickListener {
            AppUtil.hideSoftKeyboard(this)
            if (yourEdittext.text.isNotEmpty()) {
                var location: LatLng? = null
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                    val coder = Geocoder(this@WeatherMapActivity)
                    coder.getFromLocationName(yourEdittext.text.toString(), 5,object :Geocoder.GeocodeListener{
                        override fun onGeocode(addresses: MutableList<Address>) {
                            addresses.forEach {
                                //do your work android 13
                                Log.d("locationFRR", "onGeocode: ${it.latitude}")
                                Log.d("locationFRR", "onGeocode: ${it.longitude}")
                                location = LatLng(it.latitude, it.longitude)
                            }

                            location?.let {
                                Log.d("locationFRR", "onCreate: ${it.latitude}")
                                Log.d("locationFRR", "onCreate: ${it.longitude}")
                                getWeather(it.latitude.toString(), it.longitude.toString())
                            }
                        }

                        override fun onError(errorMessage: String?) {
                            super.onError(errorMessage)
                            Log.d("locationFRR", "onError: $errorMessage")
                            Toast.makeText(
                                this@WeatherMapActivity,
                                "City not found",
                                Toast.LENGTH_SHORT
                            ).show()
                        }
                    })

                } else {
                    //less than Android 13
                    //using Coroutine to avoid ANRs

                    GlobalScope.launch(Dispatchers.IO) {
                        location =
                            getLocationFromAddress(yourEdittext.text.toString())
                        withContext(Dispatchers.Main) {
                            location?.let {
                                Log.d("locationFRR", "onCreate: ${it.latitude}")
                                Log.d("locationFRR", "onCreate: ${it.longitude}")
                                getWeather(it.latitude.toString(), it.longitude.toString())
                            } ?: run {
                                Toast.makeText(
                                    this@WeatherMapActivity,
                                    "City not found",
                                    Toast.LENGTH_SHORT
                                ).show()
                            }
                        }
                    }

                }

            }
        }

 private fun getLocationFromAddress(strAddress: String): LatLng? {
        val coder = Geocoder(this)
        var p1: LatLng? = null
        try {
            val address: MutableList<Address>? = coder.getFromLocationName(strAddress, 5)

            address?.let {
                if (it.size > 0) {

                    address[0].let { add ->
                        p1 = LatLng(
                            (add.latitude),
                            (add.longitude)
                        )
                    }

                }

                Log.d("locationFRR", "getLocationFromAddress: $p1")
            }

        } catch (e: IOException) {
            e.printStackTrace()
            Log.d("locationFRR", "getLocationFromAddress: ${e.message}")
        }
        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.