Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to track a user's location and display the path travelled using Google Maps ios SDK
    primarykey
    data
    text
    <p>I'm currently building an ios app and I'm hoping to implement a function where the user's location is displayed on a Google Map view and when they move a polyline show's the path that has been travelled by the user so far. This obviously needs to happen in realtime.</p> <p>So far I've initialised a Google Maps view and can display the user's current location using the <em>observeValueForKeyPath</em> function. The view and location marker update as the user moves.</p> <p>I figured the best way to do this would be to create a GMSMutablePath object that adds the user's current location every time the map camera updates to the new location and then create a polyline from that path. The code I've used for this is below:</p> <pre><code>- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqualToString:@"myLocation"] &amp;&amp; [object isKindOfClass:[GMSMapView class]]) { [self.myMapView animateToCameraPosition:[GMSCameraPosition cameraWithLatitude:self.myMapView.myLocation.coordinate.latitude longitude:self.myMapView.myLocation.coordinate.longitude zoom:18]]; [trackedPath addCoordinate:CLLocationCoordinate2DMake(self.myMapView.myLocation.coordinate.latitude, self.myMapView.myLocation.coordinate.longitude)]; GMSPolyline *testPoly = [GMSPolyline polylineWithPath:trackedPath]; testPoly.strokeWidth = 8; testPoly.strokeColor = [UIColor redColor]; testPoly.map = myMapView; } } </code></pre> <p>This doesn't produce any polyline on the map in practice so any help/advice would be much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload