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"
Answer coordenadas -22.225985,-49.94656
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"
Answer coordenadas -22.225985,-49.94656
5
You want to perform an operation of geocoding.
Use the method Geocoder.getFromLocationName(String locationName, int maxResults).
It will return a list of objects Address, which in turn have the methods Address.getLatitude() and Address.getLongitude().
(Untested, it should actually be modified to bring the data into one thread apart, because it is too heavy for the thread home of Android):
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());
}
0
This probably won’t 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: 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 performed 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
Browser other questions tagged android google-maps google-maps-android-api-2
You are not signed in. Login or sign up in order to post.
I’m having a mistake
Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0on the lineLog.v("tag", "coordenadas " + enderecos.get(0).getLatitude() + ", " + enderecos.get(0).getLongitude());– Guilherme
That means the list of objects
Addresscame empty, that is, Google did not find an address near the given coordinates. I changed the response code to include that test.– Piovezan
Ops actually meant otherwise, that Google did not find coordinates for the address given.
– Piovezan