Note that there are some explanatory texts on larger screens.

plurals
  1. POgeocoder.getFromLocationName returns only null
    text
    copied!<p>I am going out of my mind for the last two days with an <code>IllegalArgumentException</code> 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. It is a standard code snippet that is easily found on a Google search.</p> <pre><code>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&lt;Address&gt; addresses = geocoder.getFromLocationName(strAddress, 5); if (addresses.size() &gt; 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; } </code></pre> <p>These are the permissions from manifest.xml file:</p> <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /&gt; </code></pre> <p>I do have the Google API key declared too: <code>&lt;uses-library android:name="com.google.android.maps" /&gt;</code></p> <p>From the code snippet above, <code>geocoder</code> is not <code>null</code>, neither is the <code>address</code> or <code>appContext</code>, and I stumble here: <code>geocoder.getFromLocationName(strAddress, 5);</code> </p> <p>I did a lot of Google searching and found nothing that worked, and the most important info I found is this: </p> <blockquote> <p>The Geocoder class requires a backend service that is not included in the core android framework.</p> </blockquote> <p>Sooo, I am confuzed now. What do I have to call, import, add, use in code.... to make this work? I am using Google API 2.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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload