Tell the application whether the provider has been disabled or enabled•Give the status about the provider (such as the number of satellites the GPS receiver can see), •Tell the application location informationpublic void onLocationChanged(Location location) {String locInfo = String.format("Current loc = (%f, %f) @ (%f meters up)",location.getLatitude(), location.getLongitude(),location.getAltitude() );if (lastLocation != null) {float distance = location.distanceTo(lastLocation);locInfo += String.format("\n Distance from last = %f meters", distance);}lastLocation = location;status.setText(locInfo);}
Geocoding Locations•Determining latitude and longitude is useful for precise location, tracking, and measurements.–not usually descriptive to users.•The Android SDK provides some helper methods to turn raw location data into addresses and descriptive place names.•These methods can also work in reverse, turning place names or addresses into raw location coordinates, which is referred to as reverse geocoding.
Geocoding Locations•Geocoder object doesn’t need any special permission.if (Geocoder.isPresent()) {Geocoder coder = new Geocoder(this);try {List<Address> addresses = coder.getFromLocation(location.getLatitude(), location.getLongitude(), 3);if (addresses != null) {for (Address namedLoc : addresses) {String placeName = namedLoc.getLocality();String featureName = namedLoc.getFeatureName();String country = namedLoc.getCountryName();String road = namedLoc.getThoroughfare();locInfo.append(String.format("[%s][%s][%s][%s]\n",placeName, featureName, road, country));….Location is passed in toThe onLocationChanged()