Question

I have google maps sdk on ios and enabled userlocation = yes. I want to get the user location via GPS when he moves. I could not find any method in document that returns me location updates as the user keeps moving. I want to keep my user in center of the screen by continuously then updating the camera using these location.

Any points on this? There is a method didchangecameraposition which updates when i apply gestures on maps, but not when the gps gets updated.

Was it helpful?

Solution

You cannot do it totally with the Google maps SDK, you got to use the CLLocationManger framework to get the location updates.

Initialize your locationManager to register for significant location changes and set up the delegate properly

if (nil == locationManager)
    locationManager = [[CLLocationManager alloc] init];

locationManager.delegate = self;
//Configure Accuracy depending on your needs, default is kCLLocationAccuracyBest
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;

// Set a movement threshold for new events.
locationManager.distanceFilter = 500; // meters, set according to the required value.

[locationManager startUpdatingLocation];

The Location Manger's delegate:

- (void)locationManager:(CLLocationManager *)manager
      didUpdateLocations:(NSArray *)locations {
    // If it's a relatively recent event, turn off updates to save power.
   CLLocation* location = [locations lastObject];
   NSDate* eventDate = location.timestamp;
   NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
   if (abs(howRecent) < 15.0) {
      // Update your marker on your map using location.coordinate by using the GMSCameraUpdate object

   GMSCameraUpdate *locationUpdate = [GMSCameraUpdate setTarget:location.coordinate zoom:YOUR_ZOOM_LEVEL];
   [mapView_ animateWithCameraUpdate:locationUpdate];


}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top