Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get coordinates of an address in android

How do i get gps co-ordinates of the location/address entered by user in android ?

like image 926
Rahul Baradia Avatar asked Mar 14 '12 08:03

Rahul Baradia


People also ask

Can you use your phone to find coordinates?

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.

How do I find area coordinates on my phone?

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.


2 Answers

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(); } 
like image 135
Natali Avatar answered Sep 28 '22 19:09

Natali


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.

like image 31
Tyler Treat Avatar answered Sep 28 '22 18:09

Tyler Treat