How do i get gps co-ordinates of the location/address entered by user in android ?
1. Open the Google Maps app on your iPhone or Android phone. 2. Enter the location, or select and hold to drop a pin on the map of the location you want the coordinates for.
Go to maps.google.com. 2. Type out the coordinates into the search bar — using either the degrees, minutes, and seconds (DMS) format, the degrees and decimal minutes (DMM) format, or decimal degrees (DD) format — then hit enter or click on the search icon.
Geocoder geocoder = new Geocoder(<your context>); List<Address> addresses; addresses = geocoder.getFromLocationName(<String address>, 1); if(addresses.size() > 0) { double latitude= addresses.get(0).getLatitude(); double longitude= addresses.get(0).getLongitude(); }
You can use Android's Geocoder
to do reverse geocoding:
Geocoder geocoder = new Geocoder(this, Locale.getDefault()); List<Address> addresses = geocoder.getFromLocationName(myLocation, 1); Address address = addresses.get(0); double longitude = address.getLongitude(); double latitude = address.getLatitude();
Also include the following in AndroidManifest.xml
:
<uses-permission android:name="android.permission.INTERNET"/>
Also note that you need to be using an API which includes a Geocoder
implementation. APIs which include this are the Android Google APIs for example. You can use Geocoder.isPresent()
to check if an implementation exists for your targeted API.
Check out the Geocoder
documentation for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With