Tell the application whether the provider has been disabled or enabled Give the

Tell the application whether the provider has been

This preview shows page 42 - 50 out of 68 pages.

Tell the application whether the provider has been disabled or enabledGive 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);}
Background image
Locating Your EmulatorThe Android emulator can simulate location services, but as you would expect, it does not have any “underlying hardware” to get a real satellite fix.The Android SDK provides a means to simulate location data with the use of a single location point, GPX file, or KML file.This works only with the emulator, not the physical device, but it can be useful for testing your location-based application.From Advanced AndroidTMApplication Development, Fourth Edition, by Joseph Annuzzi, Jr., Lauren Darcey, and Shane Conder(ISBN-13: 978-0-13-389238-3). Copyright © 2015 Joseph Annuzzi,
Background image
Geocoding LocationsDetermining 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.
Background image
Geocoding LocationsGeocoder 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()
Background image
Geocoding Locations….int addIdx = namedLoc.getMaxAddressLineIndex();for (int idx = 0; idx <= addIdx; idx++) {String addLine = namedLoc.getAddressLine(idx);locInfo.append(String.format("Line %d: %s\n", idx,addLine));}}}} catch (IOException e) {Log.e("GPS", "Failed to get address", e);}} else {Toast.makeText(GPSActivity.this, "No geocoding available",Toast.LENGTH_LONG).show();}
Background image
Geocoding Locations
Background image
Geocoding Locationspublic void onClick(View v) {if (Geocoder.isPresent()) {String placeName = name.getText().toString();try {// coder initialized elsewhereList<Address> geocodeResults = coder.getFromLocationName(placeName, 3);StringBuilder locInfo = new StringBuilder("Results:\n");double lat = 0f;double lon = 0f;….
Background image
Geocoding Locations….
Background image
Image of page 50

You've reached the end of your free preview.

Want to read all 68 pages?

  • Fall '12
  • JoshuaO'Connor
  • Google Maps, android location apis

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture