How to return Latitude and longitude on Android Google-Maps

1

I would like to know how I can return latitude and longitude from an address provided by the User.

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

Response coordenadas -22.225985,-49.94656

    
asked by anonymous 04.09.2014 / 21:06

2 answers

5

You want to perform a geocoding operation.

Use the Geocoder.getFromLocationName (String locationName, int maxResults) .

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

Example

(Not tested, it should actually be modified to bring the data in a separate thread as it is too heavy for the main thread of Android):

p>
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());
}
    
04.09.2014 / 22:24
0

Probably this will not be the answer but it's just to try to give a light: I get the coordinates by extracting them from a query as follows:

URL PERMANENTE : link

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

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

Exemplo :

Success

    
03.10.2014 / 19:08