Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are two steps to this:</p> <ol> <li><p>Get the current location - latitude &amp; longitude, using the GPS, network, last-known location etc. The Android <a href="http://developer.android.com/guide/topics/location/obtaining-user-location.html" rel="noreferrer">location documentation</a> includes sample code.</p></li> <li><p>Use the Android <a href="http://developer.android.com/reference/android/location/Geocoder.html" rel="noreferrer">Geocoder class</a> to request a lookup to convert the lat/long to an Address (from which you can easily extract city, country, street, etc). Specifically, you need to use the getFromLocation() method</p></li> </ol> <p>Note:</p> <ul> <li>The getFromLocation() method returns a SET of matches. In some scenarios you can show the user a set (say 5) and let them choose the best one, or you can just use the first one, assuming it's best.</li> <li>Remember that both these calls can take time. The GPS/network may take a while to provide a location. Likewise the call to getFromLocation() may take time, as it goes over the network to the Google Maps API. Therefore it is critical that you use extensive error handling for the various scenarios AND that both these calls are moved onto a separate thread so you don't lock up the app user interface (look into AsyncTask)</li> <li>The Geocoder class backend is only present on Google-approved devices. So the lookup will basically fail on any device that doesn't have GMail/Market/Maps on it.</li> </ul>
 

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