Upload
xamarin
View
1.078
Download
3
Tags:
Embed Size (px)
Citation preview
Location Based Services and Mapping with iOS
Wallace B. McClure Scalable Development, Inc.
Twi;er: @wbm Email: [email protected]
Phone: 865-‐740-‐3004
Copyrig
ht 2013, Scalable De
velopm
ent,
Inc. All Rights Reserved.
Me.About() • Wally McClure • Scalable Development, Inc. • MicrosoQ ASP.NET MVP • ASPInsider • Legend in his own mind • Author • Scalable Development, Inc. • [email protected] • 865-‐740-‐3004 • Twi;er, Facebook, LinkedIn, …
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Agenda – Mapping in iOS • LocaXon Based Services • Apple Maps • Mapping with Android • Google Maps for iOS SDK – Sample Code
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Determine Location • GPS • Cellular TriangulaXon • Wifi lookup
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Namespaces • MapKit • Apple Framework for Mapping • MonoTouch.MapKit.MKMapView class
• CoreLocaXon • Apple Framework for LocaXon Services • MonoTouch.CoreLocaXon
• CLLocaXonManager • Points
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Displaying Maps • MapKit • LaXtude/Longitude • Center • Region to display • Google Maps uses ZoomLevel
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Map Properties • MKMapView • Region • Span • Center • ShowUserLocaXon • MapType
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Annotating Maps • Points on a map • Inherit – MKAnnotaXon • Point • Title • Overlays • Add/Remove
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Displaying Overlays • Shapes • Colors • Ex: 5 km gray circle • Standard Shapes • Custom
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Map Movement • Map Delegate • Inherit from MKMapViewDelegate • Region Changed Override • Communicate back to the parent • Example Now
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Location and Change Events • LocaXon changes • StartLocaXonChanges() • StartMonitoringSignificantLocaXonChanges() • UpdatedLocaXons Event • StartUpdaXngHeading()
• Choose the right mechanism • Be a good ciXzen on the device
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Background Processing -‐ Info.plist
• Requires locaXon service • Availability of locaXon services
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Region Monitoring • Need: • Point/Center • Radius
• Check when device crosses a boundary • IdenXfier
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Tips for Conserving Battery • Turn off locaXon services when not used • Use the significant change locaXon service when possible • Use lower resoluXon for desired accuracy when possible • Turn off locaXon events if the accuracy does not improve
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Geocoding • Forward • Reverse • Network connecXon
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Forward Geocoding (iOS5) • LocaXon -‐> lat/lon pair • Not in iOS 3 or 4 • In iOS 5+! • CLGeocoder • .GeocodeAddress • Async!
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Reverse Geocoding • BuilXn • Lat/Lon -‐> Address • Built in • Async • Network connecXon • Examples in Forward and Reverse
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
But Apple Maps Has Problems • Google Maps for iOS SDK • Xamarin.iOS bindings
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Switch to Android • Different ways of thinking • Same things, just called different • MapView is deprecated • MapFragment for new development
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
• NaXve Maps applicaXon • Street View • MapAcXvity (deprecated) • MapFragment Support
Copyrig
ht 2012, Scalable
Developm
ent, Inc. All Rights
Reserved
Mapping Options
• Fragments have a different lifecycle than an AcXvity • Use OnResume • GoogleMapOpXons • CameraPosiXon • ZoomIn • ZoomOut
Copyrig
ht 2012, Scalable
Developm
ent, Inc. All Rights
Reserved
Using the MapFragment
• LocaXon Manager. • Hooks to LBS Services. • Current LocaXon. • Track Movement. • Proximity Alerts. • Interacts with LocaXon Providers.
• LocaXon Providers.
Copyrig
ht 2012, Scalable
Developm
ent, Inc. All Rights
Reserved
Main Location Elements
• Permission. • Which Provider? • Interface – ILocaXonListener. • Implement 4 methods. • Start listening. • Stop listening – as needed.
Copyrig
ht 2012, Scalable
Developm
ent, Inc. All Rights
Reserved
Where Am I
• No guarantee of any provider. • Take advantage of new providers. • Only need certain values. • Accuracy.
Copyrig
ht 2012, Scalable
Developm
ent, Inc. All Rights
Reserved
Criteria
• Example. • Implement ILocaXonListener. • Methods to implement. • Delivered in background • Example
Copyrig
ht 2012, Scalable
Developm
ent, Inc. All Rights
Reserved
Where Am I?
• Is my device in a given area? • Crossing a boundary • Similar to Regions in iOS
Copyrig
ht 2012, Scalable
Developm
ent, Inc. All Rights
Reserved
Proximity
• Forward. • Reverse. • IList<Address>. • Accuracy.
Copyrig
ht 2012, Scalable
Developm
ent, Inc. All Rights
Reserved
Geocoding
• Intent • Intent.AcXonView • Parameters: • geo: • LaXtude & Longitude • Zoom level • q
Copyrig
ht 2012, Scalable
Developm
ent, Inc. All Rights
Reserved
Native Maps Application
• Intent • Intent.AcXonView • Parameters: • LaXtude • Longitude • yaw/panorama • pitch • zoom • mapZoom Co
pyrig
ht 2012, Scalable
Developm
ent, Inc. All Rights
Reserved
Street View
Routing • Examples • iOS • Android
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
Google Maps Setup • Google Maps Key • Xamarin Component Store for Bindings • Google.Maps namespace • Apply Key • Set bundle idenXfier in Projects • Add Fragment to View
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.
• Somewhat complicated • Go to the directory: • Windows Vista/7: C:\Users\[USERNAME]\AppData\Local\Xamarin\Mono for Android\
• OSX: /Users/[USERNAME]/.local/share/Xamarin/Mono for Android/
Copyrig
ht 2012, Scalable
Developm
ent, Inc. All Rights
Reserved
Signing Key for Mapping
• keytool.exe -‐list -‐alias androiddebugkey -‐keystore debug.keystore -‐storepass android -‐keypass android
• Something like this should be returned: • androiddebugkey, Aug 16, 2011, PrivateKeyEntry, CerXficate fingerprint (MD5): AA:BB:CC:DD:EE:FF:11:22:33:44:55:66:77:88:99:00
Copyrig
ht 2012, Scalable
Developm
ent, Inc. All Rights
Reserved
Run the command
• Generate Maps API Key • h;p://code.google.com/android/maps-‐api-‐signup.html • Note: You will need a google id
Copyrig
ht 2012, Scalable
Developm
ent, Inc. All Rights
Reserved
Obtain Maps API Key
• Your map key • OpenGL • Internet • LocaXon (Fine implies Coarse)
Copyrig
ht 2012, Scalable
Developm
ent, Inc. All Rights
Reserved
Manifest File
Summary & Questions • Maps • Points on a map • Overlays • Geocoding • LocaXon Management • Power Management
Copyrig
ht 2013, Scalable
Developm
ent, Inc. All Rights
Reserved
.