Download presentation
Presentation is loading. Please wait.
Published byAndra Daniel Modified over 9 years ago
1
Lecture 13 Mobile Programming Google Maps Android API
2
Agenda Generating SHA1 Fingerprint Signing up for API Key (as developer) Permissions MapFragment and GoogleMap object Layers MyLocation
3
Google Maps API Key In order to use the Google Maps API, you first need to obtain an API key and configure your app GoogleMap API v1 is obsolete!! Now, you better use GoogleMap API v2. o https://docs.google.com/document/pub?id=19nQzvKP- CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw https://docs.google.com/document/pub?id=19nQzvKP- CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw o Please read page 863 – 970 in your textbook!
4
Getting the SHA1 Fingerprint To register for a Maps API Key, you need to provide an SHA1 fingerprint of the certificate that you will use to sign your application Navigate to C:\Documents and Settings\ \.android Run the following command keytool -list –v –keystore debug.keystore -alias androiddebugkey -storepass android -keypass android Copy the text that comes after Certificate fingerprint (SHA1): Go Google API Console and sign up for the Android Maps API Save the generated API key, you will use it in your app.
5
Use (Support) WebFragment In the layout file: You need define a Give it an id, so you can access it in source code. Class=“com.google.android.gms.maps.MapFragmen t” or SupportMapFragment depending on the version of your phone.
6
Use (Support) WebFragment In the java file: SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapView) GoogleMap map = mapGrag.getMap(); CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(x, y), where x and y are double/float. map.moveCamera(center) CameraUpdate zoom = CameraUpdateFactory.zoomTo(15). map.animateCamera(zoom)
7
Add Marker or OverlayItem Create Marker object MarkerOptions mo = new MarkerOptions().position(LatLng).title(“text”).snippet( “text”).draggable(true); Add a marker to the map object. Map.addMarker(mo);
8
Customized Info Window Create a new class that implements InfoWindowAdapter Class PopupAdapter implements InfoWindowAdapter{ LayoutInflater inflater; PopupAdapter(LayoutInflater inflater){ this.inflater = inflater; } @Override public View getInfoContents(Marker marker){ }
9
Customized Info Window @Override public View getInfoContents(Marker marker){ View popup = inflater.inflate(R.layout.popup, null); TextView tv = (TextView) popup.findViewById(); tv.setText(Marker.getTitle); return popup; } @Override Public View getInfoWindow(Marker marker) { return null;}
10
Customized Info Window In java file: map.setInfoWindowAdapter(new PopuoAdapter(getLayoutInflater()));
11
Find My Location In java file: map.setMyLocationEnabled(true); You must call map.setOnMyLocationChangeListener(Listener) The listener must override the method: Public void onMyLocationChange(Location lastKnownLocation)
12
Map Listeners setOnCameraChangeListener(this) o implement OnCameraChangeListener o Override public void onCameraChange(CameraPosition position) setMyLocationChangeListener(this): o implement OnMyLocationChangeListener o Override public void onMyLocationChange(Location lastKnownLocation) If you set marker.draggable(true) o Implement OnMarkerDragListener o Override three methods: onMarkerDrag(Marker maker) onMarkerDragEnd(Marker marker) onMarkerDragStart(Marker marker)
13
Guesture The user can change zoom level either by + and - buttons or via “pinch-to zoom” gestures The user can change the center of the map via simple swipe gestures The user can change the camera tilt via two-finger vertical swipes, so instead of a traditional top-down perspective, the user can see things on an angle The user can change the orientation of the map via a two-finger rotating swipe, to change the typical “north is to the top of the map” to some other orientation
14
Control You can enable and disable those gestures by: o setRotateGesturesEnabled() o setScrollGesturesEnabled() (for panning the map) o setTiltGesturesEnabled() o setZoomControlsEnabled() (for the + and - buttons) o setZoomGesturesEnabled() (for pinch-to-zoom) o SetCompassEnable()
15
JSON Values "title" : "IT Business Analyst Intern" "organization" : "Medtronic" "city" : "Brooklyn Park"
16
JSON Arrays "details" : [ "bla bla bla", "drank some soda", "hit manager in face with pie"]
17
JSON Objects { "title" : "IT Business Analyst Intern", "organization" : "Medtronic", "city" : "Brooklyn Park", "state" : "MN", "start_date" : "05/10", "end_date" : "07/10", "details" : [ "bla bla bla", "drank some soda", "hit manager in face with pie"] }
18
Parsing JSON JSONObject json = new JSONObject(raw); final String moviePlot = "" + json.getString("Plot"); mTextMoviePlot.post(new Runnable() { @Override public void run() { mTextMoviePlot.setText(moviePlot); } });
19
Parsing JSON JSONObject json = new JSONObject(raw); final String moviePlot = "" + json.getString("Plot"); mTextMoviePlot.post(new Runnable() { @Override public void run() { mTextMoviePlot.setText(moviePlot); } }); JSONObject is a set of name/value mappings, can represent a JSON document
20
Parsing JSON JSONObject json = new JSONObject(raw); final String moviePlot = "" + json.getString("Plot"); mTextMoviePlot.post(new Runnable() { @Override public void run() { mTextMoviePlot.setText(moviePlot); } }); Retrieve the plot of the movie
21
Parsing JSON Parsing JSON is not always this simple however, but it's usually straightforward once you understand JSON A JSONObject may consist of more JSONObjects, JSONArrays, Strings, Booleans, Integers, etc
22
Parsing JSON { "title" : "IT Business Analyst Intern", "organization" : "Medtronic", "city" : "Brooklyn Park", "state" : "MN", "start_date" : "05/10", "end_date" : "07/11", "details" : [ "bla bla bla", "drank some soda", "hit manager in face with pie"] }
23
Parsing JSON { "title" : "IT Business Analyst Intern", "organization" : "Medtronic", "city" : "Brooklyn Park", "state" : "MN", "start_date" : "05/10", "end_date" : "07/11", "details" : [ "bla bla bla", "drank some soda", "hit manager in face with pie"] } This is a JSONObject
24
Parsing JSON { "title" : "IT Business Analyst Intern", "organization" : "Medtronic", "city" : "Brooklyn Park", "state" : "MN", "start_date" : "05/10", "end_date" : "07/11", "details" : [ "bla bla bla", "drank some soda", "hit manager in face with pie"] } You can get title by calling getString("title") on the JSONObject
25
Parsing JSON { "title" : "IT Business Analyst Intern", "organization" : "Medtronic", "city" : "Brooklyn Park", "state" : "MN", "start_date" : "05/10", "end_date" : "07/11", "details" : [ "bla bla bla", "drank some soda", "hit manager in face with pie"] } You can get organization by calling getString("organization") on the JSONObject
26
Parsing JSON { "title" : "IT Business Analyst Intern", "organization" : "Medtronic", "city" : "Brooklyn Park", "state" : "MN", "start_date" : "05/10", "end_date" : "07/11", "details" : [ "bla bla bla", "drank some soda", "hit manager in face with pie"] } Etcetera, etcetera...
27
Parsing JSON { "title" : "IT Business Analyst Intern", "organization" : "Medtronic", "city" : "Brooklyn Park", "state" : "MN", "start_date" : "05/10", "end_date" : "07/11", "details" : [ "bla bla bla", "drank some soda", "hit manager in face with pie"] } This however, is not a String, but an array. Get this by calling getJSONArray() on the JSONObject
28
Parsing JSON { "title" : "IT Business Analyst Intern", "organization" : "Medtronic", "city" : "Brooklyn Park", "state" : "MN", "start_date" : "05/10", "end_date" : "07/11", "details" : [ "bla bla bla", "drank some soda", "hit manager in face with pie"] } After which you can use the getters on the JSONArray to get the desired data
29
Parsing JSON How would you represent this data using XML? { "title" : "IT Business Analyst Intern", "organization" : "Medtronic", "city" : "Brooklyn Park", "state" : "MN", "start_date" : "05/10", "end_date" : "07/11", "details" : [ "bla bla bla", "drank some soda", "hit manager in face with pie"] }
30
Parsing JSON See HttpGetJsonExample.tar
31
FACEBOOK API See FacebookApiExample.tar See FacebookHello.tar
32
References The Busy Coder's Guide to Android Development - Mark Murphy The Busy Coder's Guide to Android Development - Mark Murphy Android Developers The Mobile Lab at Florida State University
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.