Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 10)

871 views

Published on

This lecture investigates using the Google Maps SDK in an iOS application written in the Swift language. There are several inaccuracies / missing steps in the Google documentation at the date this presentation was given, so this guide was designed to help students quickly get up Google Maps up and running in their apps in minimal time. We also take a look at the basic concepts in the iOS CoreLocation framework in obtaining location information in your app in addition to using GeoCoders for forward and reverse lookups.

This lecture is part of a course intended to be an intensive and very compressed deep dive into iOS development in Swift. Visit the course web page to get copies of the course outline, lecture notes, sample code, etc.

Course website: http://www.themobilemontage.com/2015/05/12/ios-bootcamp-learning-to-create-awesome-apps-on-ios-using-swift/

Published in: Education
  • Be the first to comment

  • Be the first to like this

iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 10)

  1. 1. Working with the iOS Core Location Framework and Google Maps SDK Lecture 10 Jonathan R. Engelsma
  2. 2. TOPICS • The Fundamentals. • Working with CoreLocation • Working with Google Maps SDK
  3. 3. THE CURRENT LOCATION • The ability to obtain the device’s current location is a very powerful feature! • Enabler for context aware computing • App integrates content and behavior relevant to current location
  4. 4. OBTAININGTHE LOCATION • Smartphones use a variety of techniques to locate the device: • GPS • Assisted GPS • Cellular / WiFiTriangulation
  5. 5. GLOBAL POSITIONING SYSTEM • Space-based satellite system (US Government) • Requires line of sight to 4+ satellites • Accuracy: ~ 3 - 15 meters. • Can take time to get first fix. • Don’t work well indoors.
  6. 6. ASSISTED GPS • Greatly reduces theTTFF (time to first fix). • Uses terrestrial radio network to accelerate connection to satellite. • Widely used by modern cell phones.
  7. 7. WIFI / CELLULAR TRIANGULATION • Uses terrestrial cellular towers and wifi access points to determine device location. • Can be used indoors!
  8. 8. OBTAININGTHE LOCATION • Implication: Location data varies in accuracy. Accurate Less Accurate
  9. 9. TAKES ENERGY! • Getting a GEO fix takes a lot of battery! • device can’t sleep when GPS receiver is running. • make sure your apps don’t misuse or you will get uninstalled real fast!
  10. 10. CORE LOCATION • CoreLocation Framework • Provides apps with location coordinate and heading info. • Can define geographical regions and monitor when user crosses region boundaries. • Also supports “beacon” regions with iBeacon devices.
  11. 11. LOCATION MANAGER • CLLocationManager: var locationManager = CLLocationManager() locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.distanceFilter = 10.0 Determine how far the device must travel before a new location update is generated.
  12. 12. LOCATION ACCURACY Accuracy Technology kCLLocationAccuracyBestForNavigation GPS kCLLocationAccuracyBest GPS kCLLocationAccuracyNearestTenMeters GPS kCLLocationAccuracyHundredMeters WiFi (GPS in rural areas) kCLLocationAccuracyKilometer Cell tower kCLLocationAccuracyThreeKilometers Cell tower
  13. 13. LOCATION MANAGER • CLLocationManager requires location updates asynchronously. • View Controller typically implements the CLLocationManagerDelegate protocol to receive these updates.
  14. 14. LOCATION MANAGER DELEGATE func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) { // called when authorization changes. } func locationManagerDidResumeLocationUpdates(manager: CLLocationManager!) { // called when location updates start to arrive. }
  15. 15. LOCATION MANAGER DELEGATE func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { var location: CLLocation = locations.first as! CLLocation // put code to handle location update here. }
  16. 16. CLLOCATION • CLLocation: represents the data generated by CLLocationManager. It contains: • geo coordinates and altitude • accuracy indicator • time • speed and heading.
  17. 17. GEO CODING • CLGeocoder: converts between a lat/long coordinate and a user-friendly representation of that coordinate. Lat: 42.963661 Long: -85.677515 Grand Rapids, MI USA reverse geo-coding forward geo-coding
  18. 18. GEO-CODING GUIDELINES • Geocoder requests involve the network and are rate limited: • send one request per user action. • cache the results if you do more than one action per loc. • issue a new geocoding request only if user has moved a significant distance. • don’t use it in the background!
  19. 19. GOOGLE MAPS SDK • Google Maps SDK is the alternative of choice for Apple MapKit! • Provides more detailed map tiles. • Includes StreetView! • Can optionally use Apple’s MapKit framework https://developers.google.com/maps/documentation/ios/intro
  20. 20. GOOGLE MAPS SDK • Types: Normal, Satellite, Hybrid,Terrain • Traffic Layer • Indoor building maps where available. (Museum navigator!) • Places API / Place Picker • Panorama (StreetView) • Interactive Markers • Polygons • Camera view animation
  21. 21. DISPLAY MODES Standard Satellite StreetView
  22. 22. CREATING A MAPVIEW override func viewDidLoad() { super.viewDidLoad() locationManager.delegate = self locationManager.requestWhenInUseAuthorization() var cameraAllendale = GMSCameraPosition.cameraWithLatitude(42.96356, longitude: -85.8899, zoom: 14.7) mapView = GMSMapView.mapWithFrame(CGRectZero, camera: cameraAllendale) mapView.settings.compassButton = true self.view = mapView let marker = GMSMarker() marker.position = CLLocationCoordinate2DMake(42.96356, -85.8899) marker.title = "GVSU" marker.snippet = "Allendale, MI" marker.icon = UIImage(named: "gvsu") marker.appearAnimation = kGMSMarkerAnimationPop marker.map = mapView }
  23. 23. READING ASSIGNMENT • Chapter 21 in Programming iOS8 by Neuburg • Google Map SDK Documentation / Example Code • https://developers.google.com/maps/documentation/ios/

×