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
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
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()
.
(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());
}
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.
Success