How to return Latitude and longitude in Android Google-Maps

I would like to know how I can return latitude and longitude from a user-provided address.

Example "Av. Sampaio Vidal,Centro, Marília, SP"

Answer coordenadas -22.225985,-49.94656

Author: Franchesco, 2014-09-04

2 answers

You want to perform a geocoding operation .

Use the Geocoder method.getFromLocationName (string locationName, int maxResults).

It will return a list of objects Address, which in turn have the methods Address.getLatitude() and Address.getLongitude().

Example

(untested, it should actually be modified to bring the data into a separate thread as it is too heavy for Android's main thread):

Geocoder geocoder = new Geocoder(this);
List<Address> enderecos = geocoder.getFromLocationName("Av. Sampaio Vidal, Centro, Marília, SP", 1);
if (enderecos.size() > 0) {
    Log.v("tag", "coordenadas " + enderecos.get(0).getLatitude() + ", " + enderecos.get(0).getLongitude());
}
 5
Author: Piovezan, 2014-10-03 16:52:00

This probably won't be the answer but it's just to try to shed some light: I can get the coordinates by extracting them from a query as follows:

URL PERMANENTE: http://maps.googleapis.com/maps/api/geocode/json?address =

ENDEREÇO: Av. Sampaio Vidal, Centro, Marília, SP

Concatenates the url with the address and will have tudo on the query executed within a array, then simply extract the data you want.

Exemplo: http://maps.googleapis.com/maps/api/geocode/json?address=Av. Sampaio Vidal, Centro, Marília, SP

Success

 0
Author: Marcos Vinicius, 2014-10-03 17:08:37