public void extractGPS() {
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = lm
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f,
this);
}
With that code, we will get the GPS information from the emulator. After that we can get the name of the landmark. We start with giving permission to our application to use the Google Maps API by adding those lines to the android manifest:
First we get a geocoder object.
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
Then, we will extract the address for our current location by using the geocode object.
List addresses = geocoder.getFromLocation(latitude,longitude, 1);
We will get the first line of the address, the rest will be discarded.
Address address = addresses.get(0);
Finally, we will extract the most meaningful part of that adress.
address.getFeatureName();
That's it. That way, we will get the name of the landmark.
No comments:
Post a Comment