Set up a map

Select platform: Android iOS

To set up a map to follow a trip in iOS, complete the following steps:

  1. Initialize the map view
  2. Handle map events

Step 1: Initialize the map view

To follow a trip, you must initialize a map view.

The following example shows how to initialize GMTCMapView .

Swift

  /* 
 * MapViewController.swift 
 */ 
 class 
  
 ViewController 
 : 
  
 UIViewController 
 , 
  
 GMTCMapViewDelegate 
  
 { 
  
 private 
  
 var 
  
 rideSharingMap 
 : 
  
 GMTCMapView 
 ? 
  
 override 
  
 func 
  
 viewDidLoad 
 () 
  
 { 
  
 super 
 . 
 viewDidLoad 
 () 
  
 self 
 . 
 rideSharingMap 
  
 = 
  
 GMTCMapView 
 ( 
 frame 
 : 
  
 UIScreen 
 . 
 main 
 . 
 bounds 
 ) 
  
 self 
 . 
 rideSharingMap 
 . 
 delegate 
  
 = 
  
 self 
  
 self 
 . 
 rideSharingMap 
 ?. 
 settings 
 . 
 myLocationButton 
  
 = 
  
 true 
  
 self 
 . 
 view 
 . 
 addSubview 
 ( 
 self 
 . 
 rideSharingMap 
 !) 
  
 ... 
  
 } 
  
 } 
 

Objective-C

  /* 
 * MapViewController.h 
 */ 
 @interface 
 MapViewController 
: UIViewController<GMTCMapViewDelegate> 
 ... 
 @end 
 /* 
 * MapViewController.m 
 */ 
 @implementation 
 MapViewController 
 - 
 ( 
 void 
 ) 
 viewDidLoad 
  
 { 
  
 [ 
 super 
  
 viewDidLoad 
 ]; 
  
 ... 
  
 self 
 . 
 mapView 
  
 = 
  
 [[ 
 GMTCMapView 
  
 alloc 
 ] 
  
 initWithFrame 
 : 
 CGRectZero 
 ]; 
  
 self 
 . 
 mapView 
 . 
 settings 
 . 
 myLocationButton 
  
 = 
  
 YES 
 ; 
  
 self 
 . 
 mapView 
 . 
 delegate 
  
 = 
  
 self 
 ; 
  
 ... 
 } 
 ... 
 @end 
 

Step 2: Handle map view events

Now that you've initialized the map view, here's how to implement a delegate to handle map view event changes as the vehicle progresses along its journey.

Swift

  func 
  
 mapViewDidInitialize 
 ( 
 _ 
  
 mapview 
 : 
  
 GMTCMapView 
 ) 
  
 { 
  
 // Handle the update to the state of the map view to browsing. 
 } 
 func 
  
 mapView 
 ( 
 _ 
  
 mapView 
 : 
  
 GMSMapView 
 , 
  
 didTapConsumerMarker 
  
 mapMarker 
 : 
  
 GMSMarker 
 , 
  
 markerType 
 : 
  
 GMTCMapViewMarkerType 
 ) 
  
 - 
>  
 Bool 
  
 { 
  
 // Handle the mapView marker was tapped. 
 } 
 

Objective-C

  /* 
 * MapViewController.m 
 */ 
 #pragma mark - GMTCMapViewDelegate implementation 
 // Handle state update of map view. 
 - 
 ( 
 void 
 ) 
 mapViewDidInitializeCustomerState: 
 ( 
 GMTCMapView 
  
 * 
 ) 
 mapview 
  
 { 
  
 // Handle the update to the state of the map view to browsing. 
 } 
 - 
 ( 
 void 
 ) 
 mapView: 
 ( 
 GMSMapView 
  
 * 
 ) 
 mapView 
  
 didTapConsumerMarker 
 :( 
 nonnull 
  
 GMSMarker 
  
 * 
 ) 
 mapMarker 
  
 markerType 
 :( 
 GMTCMapViewMarkerType 
 ) 
 markerType 
  
 { 
  
 // Handle the mapView marker was tapped. 
 } 
 

What's next

Create a Mobile Website
View Site in Mobile | Classic
Share by: