Your SlideShare is downloading. ×
0
FINDING YOUR WAY             AROUND MAPKIT                                                                  by            ...
 Johnson           @_RyanJohnson_                                               MOBILE DATA SOLUTIONSMonday, April 16, 12
WHAT WE’LL COVER                       Core Location                          The Basics                         Simulatin...
CORE LOCATION                       THE
  B ACKENDMonday, April 16, 12
GETTING THE USER’S LOCATION                              CLLocationManagerMonday, April 16, 12
GETTING THE USER’S LOCATION                                             CLLocationManager              1. Instantiate a CL...
GETTING THE USER’S LOCATION                                             CLLocationManager              1. Instantiate a CL...
GETTING THE USER’S LOCATION                                              CLLocationManager              1. Instantiate a C...
GETTING THE USER’S LOCATION                                              CLLocationManager              1. Instantiate a C...
GETTING THE USER’S LOCATION                                                                                               ...
 GPS
 hates
 batteries.
 You
 can
 help
 save
 the
 user’s
                        battery
 by
 setting
 the
 desired
 accuracy
 to
 what
 you
 actually
                            need.
 Less
 accurate
Upcoming SlideShare
Loading in...5
×

Finding Your Way Around Map Kit

3,188

Published on

The basics of Core Location and Map Kit.

As presented to the MN Cocoa Heads Group for the April 2012 Meeting.

Code Available Here:
https://github.com/mobiledatasolutions/MDSMapKitDemo

Licensed Under Attribution-NonCommercial-NoDerivs 3.0
http://creativecommons.org/licenses/by-nc-nd/3.0/us/

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,188
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
27
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Finding Your Way Around Map Kit"

  1. 1. FINDING YOUR WAY AROUND MAPKIT by Ryan
  2. 2.  Johnson @_RyanJohnson_ MOBILE DATA SOLUTIONSMonday, April 16, 12
  3. 3. WHAT WE’LL COVER Core Location The Basics Simulating Location Geocoding Map Kit The Basics Annotations Overlays Advanced Drawing AnimationMonday, April 16, 12
  4. 4. CORE LOCATION THE
  5. 5.   B ACKENDMonday, April 16, 12
  6. 6. GETTING THE USER’S LOCATION CLLocationManagerMonday, April 16, 12
  7. 7. GETTING THE USER’S LOCATION CLLocationManager 1. Instantiate a CLLocationManager object: manager = [[CLLocationManager alloc] init];Monday, April 16, 12
  8. 8. GETTING THE USER’S LOCATION CLLocationManager 1. Instantiate a CLLocationManager object: manager = [[CLLocationManager alloc] init]; 2. Set a delegate: manager.delegate = (idCLLocationManagerDelegate)self;Monday, April 16, 12
  9. 9. GETTING THE USER’S LOCATION CLLocationManager 1. Instantiate a CLLocationManager object: manager = [[CLLocationManager alloc] init]; 2. Set a delegate: manager.delegate = (idCLLocationManagerDelegate)self; 3. Set your desired accuracy start monitoring: manager.desiredAccuracy = kCLLocationAccuracyBest; [manager startUpdatingLocation];Monday, April 16, 12
  10. 10. GETTING THE USER’S LOCATION CLLocationManager 1. Instantiate a CLLocationManager object: manager = [[CLLocationManager alloc] init]; 2. Set a delegate: manager.delegate = (idCLLocationManagerDelegate)self; 3. Set your desired accuracy start monitoring: manager.desiredAccuracy = kCLLocationAccuracyBest; [manager startUpdatingLocation]; 4. Location updates are sent to the delegate method: - (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;Monday, April 16, 12
  11. 11. GETTING THE USER’S LOCATION CLLocationManager 1. Instantiate a CLLocationManager object: manager = [[CLLocationManager alloc] init]; 2. Set a delegate: manager.delegate = (idCLLocationManagerDelegate)self; 3. Set your desired accuracy start monitoring: manager.desiredAccuracy = kCLLocationAccuracyBest; [manager startUpdatingLocation]; 4. Location updates are sent to the delegate method: - (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation; PROTiP:
  12. 12.  GPS
  13. 13.  hates
  14. 14.  batteries.
  15. 15.  You
  16. 16.  can
  17. 17.  help
  18. 18.  save
  19. 19.  the
  20. 20.  user’s
  21. 21.   battery
  22. 22.  by
  23. 23.  setting
  24. 24.  the
  25. 25.  desired
  26. 26.  accuracy
  27. 27.  to
  28. 28.  what
  29. 29.  you
  30. 30.  actually
  31. 31.   need.
  32. 32.  Less
  33. 33.  accurate
  34. 34.  =
  35. 35.  more
  36. 36.  battery
  37. 37.  life
  38. 38.  =
  39. 39.  better
  40. 40.  UX. manager.desiredAccuracy = kCLLocationAccuracyThreeKilometersMonday, April 16, 12
  41. 41. Geography
  42. 42.  Lesson
  43. 43.  #1: The
  44. 44.  World
  45. 45.  Is
  46. 46.  Round. Latitude
  47. 47.  =
  48. 48.  the
  49. 49.  east/west Longitude
  50. 50.  =
  51. 51.  the
  52. 52.  north/south The
  53. 53.  distance
  54. 54.  or
  55. 55.  direction
  56. 56.  between
  57. 57.  two
  58. 58.  points
  59. 59.  is
  60. 60.  calculated
  61. 61.   over
  62. 62.  the
  63. 63.  sphere
  64. 64.  of
  65. 65.  the
  66. 66.  earth
  67. 67.  not
  68. 68.  a
  69. 69.  straight
  70. 70.  line.Monday, April 16, 12
  71. 71. THE LOCATION MODEL CLLocation ➡ location.coordinate - the CLLocationCoordinate2D struct with the latitude and longitude ➡ location.horizontalAccuracy - the accuracy of the coordinate in meters ➡ location.speed - the user’s speed in meters per second ➡ location.course - the direction the user is headed in degrees Y U NO WORK!? Invalid
  72. 72.  Coordinates
  73. 73.  can
  74. 74.  cause
  75. 75.  tough
  76. 76.  to
  77. 77.  debug
  78. 78.  issues.
  79. 79.   You
  80. 80.  can
  81. 81.  validate
  82. 82.  your
  83. 83.  coordinates
  84. 84.  with CLLocationCoordinate2DIsValid(CLLocationCoordinate2D coord)Monday, April 16, 12
  85. 85. REGION MONITORING CLRegion ➡ Easy to use geofencing - lets you know when a user enters or exits a defined circular geographic region. ➡ Can continue to run in the background, relaunching your app when a user enters/exits a region. ➡ Shared system resource (limit, identifiers) ➡ Create a CLRegion to be monitored: CLLocationCoordinate2D regionCenter = {42.443904, -71.122044}; CLRegion * region = [[CLRegion alloc] initCircularRegionWithCenter:regionCenter radius:1000 identifier:@A Monitored Region]; ➡ Send the CLRegion to a CLLocationManager to be monitored [_locationManager startMonitoringForRegion:region desiredAccuracy:50]; ➡ Region events are passed to the CLLocationManager delegate’s methods: - (void) locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region; - (void) locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region;Monday, April 16, 12
  86. 86. SIMULATING YOUR LOCATION ➡ Can simulate a pin point location or travel a long a series of points ➡ If you do nothing, the simulator’s default location is in San Francisco. ➡ Three Ways to Simulate Your Location ➡ Default locations in Xcode ➡ A GPX File ➡ UIAutomation - UIATarget setLocation(coordinateDictionary) PROTIP:
  87. 87.  Only
  88. 88.  simulate
  89. 89.  your
  90. 90.  location
  91. 91.  on
  92. 92.  devices
  93. 93.   dedicated
  94. 94.  to
  95. 95.  development.
  96. 96.  Your
  97. 97.  simulated
  98. 98.  location
  99. 99.   is
  100. 100.  reported
  101. 101.  to
  102. 102.  all
  103. 103.  apps.
  104. 104.  So,
  105. 105.  Maps
  106. 106.  or
  107. 107.  Path
  108. 108.  will
  109. 109.  think
  110. 110.   you’re
  111. 111.  in
  112. 112.  Pyongyang
  113. 113.  when
  114. 114.  you’re
  115. 115.  really
  116. 116.  in
  117. 117.  Eagan.Monday, April 16, 12
  118. 118. CODE DEMO BASICS
  119. 119.   A ND
  120. 120.   LOCATION
  121. 121.   S IMULATIONMonday, April 16, 12
  122. 122. GEOCODING CLGeocoder Reverse geocoding introduced in iOS 3 with MKReverseGeocoder (now depreciated) iOS 5 now allows for forward and reverse geocoding in the new CLGeocoder class. Forward Geocoding - turns an address into a coordinate Reverse Geocoding - turns a coordinate into an addressMonday, April 16, 12
  123. 123. CODE DEMO GEOCODINGMonday, April 16, 12
  124. 124. RUNNING IN THE BACKGROUND Location services are a permitted background task Enabled in the Info.plist: keyUIBackgroundModes/key array stringlocation/string /array Region Monitoring does not require the background task permission. Your app will be relaunched in the background to allow for processing the region event.Monday, April 16, 12
  125. 125. MAP KIT THE
  126. 126.   F RONT
  127. 127.   E NDMonday, April 16, 12
  128. 128. Geography
  129. 129.  Lesson
  130. 130.  #2: Maps
  131. 131.  are
  132. 132.  flat.
  133. 133.  this
  134. 134.  is
  135. 135.  a
  136. 136.  problem. There
  137. 137.  are
  138. 138.  a
  139. 139.  lot
  140. 140.  of
  141. 141.  ways
  142. 142.  to
  143. 143.  make
  144. 144.  a
  145. 145.   circle
  146. 146.  flat.
  147. 147.  Monday, April 16, 12
  148. 148. Geography
  149. 149.  Lesson
  150. 150.  #2: Maps
  151. 151.  are
  152. 152.  flat.
  153. 153.  this
  154. 154.  is
  155. 155.  a
  156. 156.  problem. There
  157. 157.  are
  158. 158.  a
  159. 159.  lot
  160. 160.  of
  161. 161.  ways
  162. 162.  to
  163. 163.  make
  164. 164.  a
  165. 165.   circle
  166. 166.  flat.
  167. 167.  Monday, April 16, 12
  168. 168. Geography
  169. 169.  Lesson
  170. 170.  #2: Maps
  171. 171.  are
  172. 172.  flat.
  173. 173.  this
  174. 174.  is
  175. 175.  a
  176. 176.  problem. There
  177. 177.  are
  178. 178.  a
  179. 179.  lot
  180. 180.  of
  181. 181.  ways
  182. 182.  to
  183. 183.  make
  184. 184.  a
  185. 185.   circle
  186. 186.  flat.
  187. 187.   MKMapView
  188. 188.  uses
  189. 189.  a
  190. 190.  web
  191. 191.  mercator
  192. 192.   projection.Monday, April 16, 12
  193. 193. Geography
  194. 194.  Lesson
  195. 195.  #2: Maps
  196. 196.  are
  197. 197.  flat.
  198. 198.  this
  199. 199.  is
  200. 200.  a
  201. 201.  problem. There
  202. 202.  are
  203. 203.  a
  204. 204.  lot
  205. 205.  of
  206. 206.  ways
  207. 207.  to
  208. 208.  make
  209. 209.  a
  210. 210.   circle
  211. 211.  flat.
  212. 212.   MKMapView
  213. 213.  uses
  214. 214.  a
  215. 215.  web
  216. 216.  mercator
  217. 217.   projection.Monday, April 16, 12
  218. 218. Geography
  219. 219.  Lesson
  220. 220.  #2: Maps
  221. 221.  are
  222. 222.  flat.
  223. 223.  this
  224. 224.  is
  225. 225.  a
  226. 226.  problem. There
  227. 227.  are
  228. 228.  a
  229. 229.  lot
  230. 230.  of
  231. 231.  ways
  232. 232.  to
  233. 233.  make
  234. 234.  a
  235. 235.   circle
  236. 236.  flat.
  237. 237.   MKMapView
  238. 238.  uses
  239. 239.  a
  240. 240.  web
  241. 241.  mercator
  242. 242.   projection.Monday, April 16, 12
  243. 243. Geography
  244. 244.  Lesson
  245. 245.  #2: Maps
  246. 246.  are
  247. 247.  flat.
  248. 248.  this
  249. 249.  is
  250. 250.  a
  251. 251.  problem. There
  252. 252.  are
  253. 253.  a
  254. 254.  lot
  255. 255.  of
  256. 256.  ways
  257. 257.  to
  258. 258.  make
  259. 259.  a
  260. 260.   circle
  261. 261.  flat.
  262. 262.   MKMapView
  263. 263.  uses
  264. 264.  a
  265. 265.  web
  266. 266.  mercator
  267. 267.   projection.Monday, April 16, 12
  268. 268. Geography
  269. 269.  Lesson
  270. 270.  #2: Maps
  271. 271.  are
  272. 272.  flat.
  273. 273.  this
  274. 274.  is
  275. 275.  a
  276. 276.  problem. There
  277. 277.  are
  278. 278.  a
  279. 279.  lot
  280. 280.  of
  281. 281.  ways
  282. 282.  to
  283. 283.  make
  284. 284.  a
  285. 285.   circle
  286. 286.  flat.
  287. 287.   MKMapView
  288. 288.  uses
  289. 289.  a
  290. 290.  web
  291. 291.  mercator
  292. 292.   projection.Monday, April 16, 12
  293. 293. Geography
  294. 294.  Lesson
  295. 295.  #2: Maps
  296. 296.  are
  297. 297.  flat.
  298. 298.  this
  299. 299.  is
  300. 300.  a
  301. 301.  problem. There
  302. 302.  are
  303. 303.  a
  304. 304.  lot
  305. 305.  of
  306. 306.  ways
  307. 307.  to
  308. 308.  make
  309. 309.  a
  310. 310.   circle
  311. 311.  flat.
  312. 312.   MKMapView
  313. 313.  uses
  314. 314.  a
  315. 315.  web
  316. 316.  mercator
  317. 317.   projection. Mapkit
  318. 318.  uses
  319. 319.  its
  320. 320.  own
  321. 321.  structures
  322. 322.   (MKMapPoint,
  323. 323.  MKMapRect)
  324. 324.  to
  325. 325.   handle
  326. 326.  this
  327. 327.  conversionMonday, April 16, 12
  328. 328. MAPS MKMapView The basic way of showing geographic data Can show the user’s location with out the need for Core Location mapview.showsUserLocation = YES; [mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];Monday, April 16, 12
  329. 329. ANNOTATIONS MKAnnotation + MKAnnotationView The basic way of presenting point data on a map Comes with a disclosure pop-out for additional detail MKAnnotation is the basic model (really a protocol) and MKAnnotationView is the view. You add the MKAnnotation to the map, and the map is provided a view by the map’s delegate.Monday, April 16, 12
  330. 330. OVERLAYS MKOverlay + MKOverlayView Allows you to place paths or custom drawing over a map. Provided basic path types: MKCircle, MKPolyline, MKPolygon Can create your own view classes to easily draw over a map. Custom drawing must be done by overriding: - (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context;Monday, April 16, 12
  331. 331. CODE DEMO ANNOTATIONS
  332. 332.   +
  333. 333.   O VERLAYSMonday, April 16, 12
  334. 334. GDAL Geospatial Data Abstraction Library www.gdal.com or brew install gdal A command line tool to create your own tile images and to convert the projection of images Essential if you’re going to put your own images on a mapMonday, April 16, 12
  335. 335. CODE DEMO TILED
  336. 336.   I MAGESMonday, April 16, 12
  337. 337. ADDITIONAL RESOURCES WWDC Videos Sample Code - 2010 Session - Customizing Maps With Overlays KML https://developer.apple.com/library/ios/samplecode/KMLViewer/ Introduction/Intro.html#//apple_ref/doc/uid/DTS40010046 Tiled Images (in the Code Bundle) http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/ getSoftware? wosid=aY5boO0HQiIJ3STghf12IbXXhCtfileID=26713code=ysource=x 2011 Session - Visualizing Information Graphically With MapKit Open Source Code - VPPMap (Annotation Clustering)- https://github.com/vicpenap/VPPMap Core Location Utils - https://github.com/100grams/CoreLocationUtilsMonday, April 16, 12
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×