0

I am using Google Maps SDK to get the current location. My doubt is, how to do location updates using the delegate methods using Google Maps SDK. Is there any delegate methods for getting the current location and location updates?

@implementation MyLocationViewController {
    GMSMapView *mapView_;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868 longitude:151.2086 zoom:12];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.settings.compassButton = YES;
    mapView_.settings.myLocationButton = YES;

    // Listen to the myLocation property of GMSMapView.
    [mapView_ addObserver:self forKeyPath:@"myLocation"
    options:NSKeyValueObservingOptionNew context:NULL];

    self.view = mapView_;

    // Ask for My Location data after the map has already been added to the UI.
    dispatch_async(dispatch_get_main_queue(), ^{
        mapView_.myLocationEnabled = YES;
    });
}
Pang
  • 9,564
  • 146
  • 81
  • 122
  • You should be using "Google Maps" to display location on your iOS device. To get current location and repeated updates you should use "CLLocationManager". Let me know if any help needed. – iCoderz Developers Jun 01 '17 at 10:56
  • @iCoderzDevelopers Thanks for your response. can you send me any sample code for update location. i need a delegate method.. for that one.. i am new to ios development – user3214012 Jun 01 '17 at 11:11

2 Answers2

0

In order to get current location on iOS , refer to following link:

How can I get current location from user in iOS

-1

You can use CLLocationManager delegate methods to update location and set the location to the map.

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;

This delegate method will update the location. Inside the method, you can set the map view to the coordinates received.

_currentLocation = [locations lastObject];
CLLocationCoordinate2D target =
    CLLocationCoordinate2DMake(_currentLocation.coordinate.latitude, _currentLocation(This is the current location of the user).coordinate.longitude);
_googleMap.camera = [GMSCameraPosition cameraWithTarget:target zoom:16];
Pang
  • 9,564
  • 146
  • 81
  • 122
Rajesh Bajaj
  • 133
  • 1
  • 9