geocoder.getFromLocationName returns only null
Posted
by
test
on Stack Overflow
See other posts from Stack Overflow
or by test
Published on 2010-12-31T00:04:13Z
Indexed on
2010/12/31
1:54 UTC
Read the original article
Hit count: 510
android
|google-geocoder
Hello, I am going out of my mind for the last 2 days with an IllegalArgumentException error i receive in android code when trying to get a coordinates out of an address, or even reverse, get address out of longitude and latitude. this is the code, but i cannot see an error. is a standard code snippet that is easily found on a google search.
public GeoPoint determineLatLngFromAddress(Context appContext,
String strAddress) {
Geocoder geocoder = new Geocoder(appContext,
Locale.getDefault());
GeoPoint g = null;
try {
System.out.println("str addres: " + strAddress);
List<Address> addresses = geocoder.getFromLocationName(strAddress,
5);
if (addresses.size() > 0) {
g = new GeoPoint((int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
}
} catch (Exception e) {
throw new IllegalArgumentException("locationName == null");
}
return g;
}
These are the permissions from manifest.xml file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
I do have the Google Api key declared too: <uses-library android:name="com.google.android.maps" />
From the code snippet above, geo coder is not null, neither is the address or appContext, and i stumble here: geocoder.getFromLocationName(strAddress, 5);
I did a lot of google searching and found nothing that worked, and the most important info i found is this: ""The Geocoder class requires a backend service that is not included in the core android framework." Sooo, i am confuzed now. What do I have to call, import, add, use in code.... to make this work? I am using Google Api2.2, Api level 8. If somebody has found a solution for this, or a pointer for documentation, something that i didn't discover, please let us know. Thank you for your time.
© Stack Overflow or respective owner