cs378 - mobile computing
DESCRIPTION
CS378 - Mobile Computing. Maps. Using Google Maps. Like other web services requires an API key from Google http:// code.google.com/android/add-ons/google-apis/mapkey.html required to use MapView class Must: - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/1.jpg)
CS378 - Mobile Computing
Maps
![Page 2: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/2.jpg)
2
Using Google Maps• Like other web services requires an API key
from Google• http://
code.google.com/android/add-ons/google-apis/mapkey.html• required to use MapView class• Must:–Register the MD5 fingerprint of the certificate
used to sign the application. – Adding a reference to the Maps API Key in
each MapView (xml or code)
![Page 3: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/3.jpg)
3
Signing Apps• deploying apps on the market requires signing
the app with a certificate• development and debugging uses an
automatic key creation process– invisible to us
• In release mode you must create your own private key to sign apps– use of keytool program from Java SDK
• http://developer.android.com/guide/publishing/app-signing.html
![Page 4: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/4.jpg)
4
Debugging Maps Applications• Possible to use the debug key to get a
certificate for Google Maps• steps:– locate debug keystore–use keytool to get the MD5 fingerprint of the
debug certificate to request map certificate• MD5–Message - Digest Algorithm– cryptographic hash function
![Page 5: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/5.jpg)
5
Debug Key• Portion of debug.keystore
![Page 6: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/6.jpg)
6
Getting MD5 Fingerprint• use keytool program• keytool part of Java SDK• keytool -list -alias androiddebugkey
-keystore <path_to_debug_keystore>.keystore -storepass android -keypass android• gives MD5 fingerprint of the debug
certificate• keytool of Java 1.7 gives SHA1 by default–use -v after keytool, before -list
![Page 7: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/7.jpg)
7
Google Maps Terms of Service• Some Highlights
–may include ads in future– Google may limit number of transactions– Cannot use for turn-by-turn directions or
autonomous driving
![Page 8: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/8.jpg)
8
Debug API Key
![Page 9: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/9.jpg)
9
Hello MapView• Build Target - Google, not Android
• MapView not a standard Android class–part of Google Maps Library– add to manifest
• must also include INTERNET permission and LOCATION permission
![Page 10: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/10.jpg)
10
Aside Permissions• http://
developer.android.com/reference/android/Manifest.permission.html
![Page 11: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/11.jpg)
11
MapView• A type of view for layout file
![Page 12: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/12.jpg)
12
MapActivity• Create class that extends MapActivity
instead of Activity• import com.google.android.maps.MapActivity;
• must implement isRouteDisplayed method
• must return true if any kind of route (to be followed) is displayed, per terms of use
![Page 13: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/13.jpg)
13
Instance Vars and onCreate• Add instance variables and initialize in
onCreate method
![Page 14: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/14.jpg)
14
HelloMapView• Run app• Displays map and allows panning and zooming
![Page 15: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/15.jpg)
15
Customizing Map• Easy to display map and allow interaction• Customize with markers and overlays• Overlays–used to display information on top of map–use ItemizedOverlay class
![Page 16: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/16.jpg)
16
ItemizedOverlay
![Page 17: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/17.jpg)
17
ItemizedOverlay• populate method will call createItem• define createItem and return value from
the ArrayList instance var• define size method that returns number
of overlay items
![Page 18: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/18.jpg)
18
Adding Overlays• In MapActivity create OverlayItem• add to HelloItemizedOverlay• add to MapView• Need a drawable for the marker– res/drawable– issues display gif
format imageson some devices
![Page 19: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/19.jpg)
19
Changes to HelloMapView
![Page 20: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/20.jpg)
20
Add Overlay Items• Create GeoPoint and use these to create
OverlayItems• GeoPoint based on microdegrees– lat and long times 1,000,000
• Build OverlayItems out of GeoPoints and include strings for title and snippet text to display when drawable clicked
![Page 21: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/21.jpg)
21
addOverlays method in HelloMapView
![Page 22: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/22.jpg)
22
Result• one overlay
with multiple items• based on
locations we added
![Page 23: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/23.jpg)
23
Display Information• To display information (title and snippet)
of overlay override the onTap method in the ItemizedOverlay class
![Page 24: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/24.jpg)
24
Results of Clicking Longhorn
![Page 25: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/25.jpg)
25
Reverse Geocoding• Find addresses from longitude/latitude• Geecoder uses a backend that is NOT
included in the core android framework• use isPresent method to check for service
location = locationManager.getLastKnownLocation( LocationManager.GPS_PROVIDER); double lat = location.getLatitude(); double lng = location.getLongitude(); Geocoder gc = new Geocoder(this, Locale.getDefault()); List<Address> addresses = null; try { addresses = gc.getFromLocation(lat, lng, 5); // maxResults } catch (IOException e) {}
![Page 26: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/26.jpg)
26
Forward Geocoding• Find longitude/latitude (and more) from
address or airport code Geocoder gc = new Geocoder(this, Locale.US); List<Address> addresses = null; try { addresses = gc.getFromLocationName( “713 N. Duchese, St. , Missouri”, 5); } catch (IOException e) {} double lat = addresses.get(0).getLatitude(); double lng = addresses.get(0). getLongitude (); String zip = addresses.get(0).getPostalCode();
![Page 27: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/27.jpg)
27
Maps Example• Route Tracker using
Locations, MapActivity, MapView, and Google Maps– from Deitel AFP-AADA
• Similar to Map My Ride–popular app among
cyclists and runners
![Page 28: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/28.jpg)
28
RouteTracker App
![Page 29: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/29.jpg)
29
RouteTracker App• using FrameLayout to stack components
with the most recently added component on top
• ToggleButton at bottom to start and stop route tracking
• MapView added to FrameLayout• route is an overlay to map with points
and lines connecting points
![Page 30: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/30.jpg)
30
RouteTracker ClassesRouteTracker
Starting Activitydeals with LocationProvider
RouteOverlayOverlay with location points
(every 10th)and lines connecting.Converts locations to
GeoPoints.Overloads draw
BearingFrameLayoutDisplays MapView
rotates based on bearing from location
![Page 31: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/31.jpg)
31
Criteria Class• Set criteria for selecting a LocationProvider
![Page 32: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/32.jpg)
32
GpsStatus.Listener• Responds to changes in GPS status• Are we receiving GPS fixes?• App does not track unless this is true
![Page 33: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/33.jpg)
33
Simulating GPS Data• to simulate
changes in location in emulator• GPS data in a
file–GPS Exchange
Format (GPX)
![Page 34: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/34.jpg)
34
Creating GPX Files• Many apps and programs• One option for Android devices• GPSLogger• gpsbabel to
convertbetweenvarious GPS formats– gpx has different versions
![Page 35: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/35.jpg)
35
Running GPX files in App• DDMS • Emulator Control Tab• GPX Tab• Load
![Page 36: CS378 - Mobile Computing](https://reader035.vdocument.in/reader035/viewer/2022081512/56816109550346895dd0535d/html5/thumbnails/36.jpg)
36
Running GPX