36
Location Based Services and Mapping with iOS Wallace B. McClure Scalable Development, Inc. Twi;er: @wbm Email: [email protected] Phone: 8657403004 Copyright 2013, Scalable Development, Inc. All Rights Reserved.

Mapping on iOS and Android, Wally McClure

  • Upload
    xamarin

  • View
    1.079

  • Download
    3

Embed Size (px)

Citation preview

Page 1: Mapping on iOS and Android, Wally McClure

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.  

Page 2: Mapping on iOS and Android, Wally McClure

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

.  

Page 3: Mapping on iOS and Android, Wally McClure

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

.  

Page 4: Mapping on iOS and Android, Wally McClure

Determine  Location  •  GPS  •  Cellular  TriangulaXon  •  Wifi  lookup  

Copyrig

ht  2013,  Scalable  

Developm

ent,  Inc.        All  Rights  

Reserved

.  

Page 5: Mapping on iOS and Android, Wally McClure

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

.  

Page 6: Mapping on iOS and Android, Wally McClure

Displaying  Maps  •  MapKit  •  LaXtude/Longitude  •  Center  •  Region  to  display  •  Google  Maps  uses  ZoomLevel  

Copyrig

ht  2013,  Scalable  

Developm

ent,  Inc.        All  Rights  

Reserved

.  

Page 7: Mapping on iOS and Android, Wally McClure

Map  Properties  •  MKMapView  •  Region  •  Span  •  Center  •  ShowUserLocaXon  •  MapType  

Copyrig

ht  2013,  Scalable  

Developm

ent,  Inc.        All  Rights  

Reserved

.  

Page 8: Mapping on iOS and Android, Wally McClure

Annotating  Maps  •  Points  on  a  map  •  Inherit  –  MKAnnotaXon  •  Point  •  Title  •  Overlays  •  Add/Remove  

Copyrig

ht  2013,  Scalable  

Developm

ent,  Inc.        All  Rights  

Reserved

.  

Page 9: Mapping on iOS and Android, Wally McClure

Displaying  Overlays  •  Shapes  •  Colors  •  Ex:  5  km  gray  circle  •  Standard  Shapes  •  Custom  

Copyrig

ht  2013,  Scalable  

Developm

ent,  Inc.        All  Rights  

Reserved

.  

Page 10: Mapping on iOS and Android, Wally McClure

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

.  

Page 11: Mapping on iOS and Android, Wally McClure

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

.  

Page 12: Mapping on iOS and Android, Wally McClure

Background  Processing  -­‐  Info.plist  

•  Requires  locaXon  service  •  Availability  of  locaXon  services  

Copyrig

ht  2013,  Scalable  

Developm

ent,  Inc.        All  Rights  

Reserved

.  

Page 13: Mapping on iOS and Android, Wally McClure

Region  Monitoring  •  Need:  •  Point/Center  •  Radius  

•  Check  when  device  crosses  a  boundary  •  IdenXfier  

Copyrig

ht  2013,  Scalable  

Developm

ent,  Inc.        All  Rights  

Reserved

.  

Page 14: Mapping on iOS and Android, Wally McClure

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

.  

Page 15: Mapping on iOS and Android, Wally McClure

Geocoding  •  Forward  •  Reverse  •  Network  connecXon  

Copyrig

ht  2013,  Scalable  

Developm

ent,  Inc.        All  Rights  

Reserved

.  

Page 16: Mapping on iOS and Android, Wally McClure

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

.  

Page 17: Mapping on iOS and Android, Wally McClure

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

.  

Page 18: Mapping on iOS and Android, Wally McClure

But  Apple  Maps  Has  Problems  •  Google  Maps  for  iOS  SDK  •  Xamarin.iOS  bindings  

Copyrig

ht  2013,  Scalable  

Developm

ent,  Inc.        All  Rights  

Reserved

.  

Page 19: Mapping on iOS and Android, Wally McClure

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

.  

Page 20: Mapping on iOS and Android, Wally McClure

•  NaXve  Maps  applicaXon  •  Street  View  •  MapAcXvity  (deprecated)  •  MapFragment  Support  

Copyrig

ht  2012,  Scalable  

Developm

ent,  Inc.  All  Rights  

Reserved

 

Mapping  Options  

Page 21: Mapping on iOS and Android, Wally McClure

•  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  

Page 22: Mapping on iOS and Android, Wally McClure

•  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  

Page 23: Mapping on iOS and Android, Wally McClure

•  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  

Page 24: Mapping on iOS and Android, Wally McClure

•  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  

Page 25: Mapping on iOS and Android, Wally McClure

•  Example.  •  Implement  ILocaXonListener.  •  Methods  to  implement.  •  Delivered  in  background  •  Example  

Copyrig

ht  2012,  Scalable  

Developm

ent,  Inc.  All  Rights  

Reserved

 

Where  Am  I?  

Page 26: Mapping on iOS and Android, Wally McClure

•  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  

Page 27: Mapping on iOS and Android, Wally McClure

•  Forward.  •  Reverse.  •  IList<Address>.  •  Accuracy.  

Copyrig

ht  2012,  Scalable  

Developm

ent,  Inc.  All  Rights  

Reserved

 

Geocoding  

Page 28: Mapping on iOS and Android, Wally McClure

•  Intent  •  Intent.AcXonView  •  Parameters:  •  geo:  •  LaXtude  &  Longitude  •  Zoom  level  •  q  

Copyrig

ht  2012,  Scalable  

Developm

ent,  Inc.  All  Rights  

Reserved

 

Native  Maps  Application  

Page 29: Mapping on iOS and Android, Wally McClure

•  Intent  •  Intent.AcXonView  •  Parameters:  •  LaXtude  •  Longitude  •  yaw/panorama  •  pitch  •  zoom  •  mapZoom   Co

pyrig

ht  2012,  Scalable  

Developm

ent,  Inc.  All  Rights  

Reserved

 

Street  View  

Page 30: Mapping on iOS and Android, Wally McClure

Routing  •  Examples  •  iOS  •  Android  

Copyrig

ht  2013,  Scalable  

Developm

ent,  Inc.        All  Rights  

Reserved

.  

Page 31: Mapping on iOS and Android, Wally McClure

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

.  

Page 32: Mapping on iOS and Android, Wally McClure

•  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  

Page 33: Mapping on iOS and Android, Wally McClure

•  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  

Page 34: Mapping on iOS and Android, Wally McClure

•  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  

Page 35: Mapping on iOS and Android, Wally McClure

•  Your  map  key  •  OpenGL  •  Internet  •  LocaXon  (Fine  implies  Coarse)  

Copyrig

ht  2012,  Scalable  

Developm

ent,  Inc.  All  Rights  

Reserved

 

Manifest  File  

Page 36: Mapping on iOS and Android, Wally McClure

Summary  &  Questions  •  Maps  •  Points  on  a  map  •  Overlays  •  Geocoding  •  LocaXon  Management  •  Power  Management  

Copyrig

ht  2013,  Scalable  

Developm

ent,  Inc.        All  Rights  

Reserved

.