A quick guide on how to get started with Google Maps Android API v2 and Google Maps SDK for iOS with some GIS fun facts that can be learnt along the way.
Starting with a quick overview of the key features of both SDK.
followed by setup instructions, code snippets and some tips on utilizing geotagged information.
Maps Rock!
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
Google Maps Mobile APIs by Kasia Derc-Fenske
1. Kasia Derc-Fenske
Google Maps Mobile APIs
@kaskaderc +Kasia Derc-Fenske // Google
kaskaderc
Friday, March 22, 13 1
2. Google Maps Mobile APIs
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Google Maps Google Maps
Android API v2 SDK for iOS
Friday, March 22, 13 2
4. Goal of this presto
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Friday, March 22, 13 4
5. Key features
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Android iOS
Development: Xcode 4.5+, iOS SDK 6.+.
API level 12 (level 4 w/Support Library),
Platforms Target platform: iOS 5.1
GLES 2
Vector Maps 3D Buildings, Roadmap, Hybrid Map, Satellite Imagery, Terrain Map
Camera Positioning Zoom, Pan, Tilt, Bearing, Animation
Markers & Info
Custom Icons, Anchoring, Dragging (Android), Custom Info Windows
Windows
Drawing Polylines (geodesic), Polygons, and Circles Polylines (geodesic)
Overlays Ground and Tile Ground
Layers Traffic and Indoor (Android)
Friday, March 22, 13 5
6. Before you start
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Things you need to do to
use the APIs.
Friday, March 22, 13 6
7. Getting started
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Services Section
API Access section
Friday, March 22, 13 7
8. Getting started
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
API Access section
13:4A:53:3D:F7:B6:20:...:2C:01:58:F2:C8:36:6A;com.example.mapdemo
Certificate
debug
◦ OS X and Linux: ~/.android/
◦ Windows Vista and Windows 7: C:Usersyour_user_name.android
release
http://
developer.android.com/
tools/publishing/app-
signing.html#releasemo
Getting the fingerprint de
%> keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -
storepass android -keypass android
Friday, March 22, 13 8
9. The important NOT s
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
• MapView v1 keys will NOT work with the new v2 API
• The key is generated in the Google APIs Console, NOT the Google Play
Developer Console
Friday, March 22, 13 9
10. +Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
iOS demo
Friday, March 22, 13 10
11. Demo time !
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Friday, March 22, 13 11
12. iOS demo code
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Run it!
Friday, March 22, 13 12
13. GIS Trivia 1
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Designed by Ben King (http://thenounproject.com/Kinger/)
Friday, March 22, 13 13
14. GIS Trivia 1
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
The earth is not flat!
Friday, March 22, 13 14
15. What is a geodesic ?
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
• the path followed by an object with not
forces acting on it
• the “straightest” you can get in curved
space
• it’s about pinning a string to two points
on earth and making it as short as
possible
Friday, March 22, 13 15
16. Going from New York to Rome
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Friday, March 22, 13 16
17. +Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Android demo
Friday, March 22, 13 17
18. How does it work: Google Play .apk
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Friday, March 22, 13 18
19. Setting up ADT
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
What we need:
• ADT: http://developer.android.com/sdk/
• Google Play Services
• Android Support Library
Note: Sample code is also bundled with Google Play Services SDK
Friday, March 22, 13 19
20. Android Support Library
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
• Use SupportMapFragment is targeting API 11 or below
• Also required for example app
Friday, March 22, 13 20
21. Setting up ADT
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
• import
sdk/extras/google/google_play_services/libproject/google-
play-services_lib
sdk/extras/google/google_play_services/samples/maps
• add
android/compatibility/v4/android-support-v4.jar
as an external jar
Friday, March 22, 13 21
22. AndroidManifest.xml
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Friday, March 22, 13 22
23. Become a developer
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Plug in a physical phone
Enable debugging and Run!
Friday, March 22, 13 23
24. GIS Trivia 2: Projections
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Designed by Ben King (http://thenounproject.com/Kinger/)
Friday, March 22, 13 24
25. GIS Trivia 2: XKCD Mercator
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
source: http://imgs.xkcd.com/comics/map_projections.png
Friday, March 22, 13 25
26. GIS Trivia 2: Mercator
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
http://kaskaderc.github.com/
maps_samples/projections/mercator.html
Friday, March 22, 13 26
27. What’s available
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Android Maps Api
Features
Friday, March 22, 13 27
35. 5. Markers & InfoWindows
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Friday, March 22, 13 35
36. 5. Markers and Info Windows
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
map.addMarker(new MarkerOptions()
.position(new LatLng(37.5, 122.5))
.title("Title") // optional
.snippet("And a Snippet!") //
optional
.draggable(true) // optional
.visible(true)); // optional
Friday, March 22, 13 36
37. 5. Markers and Info Windows
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
map.addMarker(new MarkerOptions()
.position(new LatLng(40, 40))
.icon(BitmapDescriptorFactory.defaultMarker(
BitmapDescriptorFactory.HUE_AZURE))); // float hue 0-359
map.addMarker(new MarkerOptions()
.position(new LatLng(50, 50))
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.marker)));
// or fromAsset(String), fromBitmap(Bitmap), fromFile(String)
map.addMarker(new MarkerOptions()
.position(new LatLng(60, 60))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_shadow))
.anchor(.23f, 1)); // ratio of width & height from top-left corner
Friday, March 22, 13 37
38. 5. Markers and Info Windows
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
(1.0,0.0)
←u→
←v→
(0.8,0.4)
(1.0,1.0)
(0.0,1.0) (0.5,1.0)
[default]
Friday, March 22, 13 38
39. Custom info windows
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
• Create a InfoWindowAdapter
class CustomInfoWindowAdapter implements InfoWindowAdapter {
@Override
public View getInfoContents(Marker marker) {
return null; // return null for default InfoWindow
}
@Override
public View getInfoWindow(Marker marker) {
return null; // call getInfoContents
}
}
• Attach the adapter to the map
Friday, March 22, 13 39
40. Marker and Info Window Events!
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
• Defining Listeners
public class MarkerActivity extends android.support.v4.app.FragmentActivity
implements OnMarkerClickListener, OnInfoWindowClickListener,
OnMarkerDragListener {
...
• Registering Listeners
map.setOnMarkerClickListener(this);
map.setOnInfoWindowClickListener(this);
map.setOnMarkerDragListener(this);
• Receiving Events
public void onMarkerDrag(Marker marker) {}
public void onMarkerDragEnd(Marker marker) {}
public void onMarkerDragStart(Marker marker) {}
public void onInfoWindowClick(Marker marker) {}
public boolean onMarkerClick(Marker marker) {}
Friday, March 22, 13 40
41. 6. Polylines & Polygons
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Friday, March 22, 13 41
43. 6. Fragment Support
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Friday, March 22, 13 43
44. 6. Fragment Support
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
MultiMapDemoActivity.java
public class MultiMapDemoActivity extends
android.support.v4.app.FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.multimap_demo);
}
} <LinearLayout xmlns:android=...
xmlns:map=...
android:id="@+id/map_container"
...
<fragment
<LinearLayout android:id="@+id/map1"
android:id="@+id/map_container2" <fragment
android:id="@+id/map2"
Friday, March 22, 13 44
45. 7. Tile Overlays
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Friday, March 22, 13 45
46. Hello Map and getting started
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Shortcuts: Kick-start Google Maps Android API v2 Development
https://www.youtube.com/watch?v=VecPbAK5U4M
http://github.com/googlemaps/hellomap-android
Friday, March 22, 13 46
47. GIS Trivia 3: Projections c.d.
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Designed by Ben King (http://thenounproject.com/Kinger/)
Friday, March 22, 13 47
48. GIS Trivia 3: XKCD Gall-Peters
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
source: http://imgs.xkcd.com/comics/map_projections.png
Friday, March 22, 13 48
49. GIS Trivia 3: Gall - Peters projection
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
http://kaskaderc.github.com/
maps_samples/projections/gallpeters.html
Friday, March 22, 13 49
50. GIS Trivia 3: XKCD and Projections
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
http://xkcd.com/977/
source: http://imgs.xkcd.com/comics/map_projections.png
Friday, March 22, 13 50
51. Maps SDK for iOS Features and Sample
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Maps SDK for iOS Features
Friday, March 22, 13 51
52. 1. Basic Maps in 3D, map types, traffic layer
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Friday, March 22, 13 52
53. 2. Polylines, Custom Markers, Ground Overlay...
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Friday, March 22, 13 53
54. Let’s check sample projects!
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Instead or
reiterating sample
code let’s see how to
use storyboards and
look at the event
model.
Friday, March 22, 13 54
55. Getting started iOS project
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
getting started project
Friday, March 22, 13 55
56. Using storyboards
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Friday, March 22, 13 56
58. From the Controller’s perspective
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
We will implement some of the Map delegate functions
@interface googleMainController : declared in
UIViewController<GMSMapViewDelegate> GMSMapView.h
We will tell the map we will be it’s delegate
self.googleMap.delegate = self;
Friday, March 22, 13 58
65. iOS Demo App : Earthquakes on the Move
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Find out by watching Maps Developer
Shortcuts!
Shortcuts: Earthquakes on the Move
https://www.youtube.com/watch?v=xZt5ZIWWUd0
Friday, March 22, 13 65
66. Launching native Google Maps app
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Android intents
Uri uri = Uri.parse("http://maps.google.com/maps?saddr=FROM_LOCATION&daddr=TO_LOCATION");
Uri uri = Uri.parse("geo:13.070984,80.253639");
Intent in = new Intent(Intent.ACTION_VIEW, uri);
startActivity(in);
iOS URL Scheme
[[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@"comgooglemaps://"]];
comgooglemaps://?saddr=Google+Inc,+8th+Avenue,+New+York,
+NY&daddr=John+F.+Kennedy+International+Airport,+Van+Wyck
+Expressway,+Jamaica,+New+York&directionsmode=transit
Friday, March 22, 13 66
67. Google Maps Web Services - Server side
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
100K requests per 24 hour period ( if billing is enabled )
Places API: Detailed information about (80M+) places
across a wide range of categories.
2500 requests per day
Directions API: Directions for several modes of transportation
(transit, driving, walking or cycling) between locations, including waypoints.
Distance Matrix API: Travel distance and time for a matrix of locations.
Elevation API: Elevation data for all locations on the surface of the earth,
including depth locations on the ocean floor.
Geocoding API: Forward and reverse geocoding.
Time Zone API: Time offset data for locations on Earth.
Friday, March 22, 13 67
68. GIS Trivia 4: Maps Surprises
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Designed by Ben King (http://thenounproject.com/Kinger/)
Friday, March 22, 13 68
69. GIS Trivia 4: be surprised
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Friday, March 22, 13 69
70. GIS Trivia 4: True size of Africa by Kai Krause
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
full image: http://www.learnnc.org/lp/multimedia/16023
Friday, March 22, 13 70
71. Getting in touch
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
https://developers.google.com/maps/forum/
Friday, March 22, 13 71
72. Issue tracker
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Issue tracker
code.google.com
Friday, March 22, 13 72
73. Asking questions
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Friday, March 22, 13 73
74. Staying tuned
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
developers.google.com/maps
Google Maps API (G+ & Twitter)
Google Geo Developers Blog
Google Maps API Developers Live
Friday, March 22, 13 74
75. Extra tips
+Kasia Derc-Fenske kaskaderc Kasia Derc-Fenske | Google
Add
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"/>
into AndroidManifest.xml to ensure correct behavior under poor connectivity conditions
Friday, March 22, 13 75
76. Kasia Derc-Fenske
Thank you!
@kdf +Kasia Derc-Fenske // Google
kaskaderc
@ +alfredomorresi Alfredo Morresi // Google Italy
rainbowbreeze
Friday, March 22, 13 76