With a few lines of code you can to detect your address, lat, long from map, just intent to location activity with result and click pick location button affter detecting your location on map to start geocoding process to get your address.
Usage To use the LocationPickerActivity first you need to add these lines to your AndroidManifest file:
<activity
android:name="mostafa.projects.location_picker.activities.LocationActivity"
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar"
android:windowSoftInputMode="adjustPan"
>
</activity>
var locationIntent = Intent(this, LocationActivity::class.java)
startActivityForResult(locationIntent, 2021)
then override onActivityResult abd get your data ( City, Country, State, Postal Code, Address )
NOTE:: May one of these params can be null.
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK && requestCode == 2021) {
var address = data?.getSerializableExtra("addressDetected") as Address
address.city?.let {
city_name_txt.setText("City = ${address.city}")
}
address.state?.let {
state_name_txt.setText("State = ${address.state}")
}
address.country?.let {
country_name_txt.setText("Country = ${address.country}")
}
address.postalCode?.let {
postalCode_name_txt.setText("Postal Code = ${address.postalCode}")
}
address.knownName?.let {
knownName_name_txt.setText("Known name = ${address.knownName}")
}
address.lat?.let {
latlong_name_txt.setText("LatLong = ${address.lat} , ${address.long}")
}
}
}
allprojects
{
repositories
{
maven { url 'https://jitpack.io' }
}
}
implementation 'com.github.MostafaGad1911:LocationPicker:1.1.3'