5

i am using Latest Google Map SDK for iOS in which i am not able to rotate Map like below.

For Eg. MKMapview is able to rotate it with Compass Heading.

[mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];

So My Question is is there any buddy help me out to find out how to Get that thing to be done in Google MAP SDK.

i have referred every thing about Google Map SDK i din't find any such property or any method to rotate Map according Device Compass value.

i have referred this link about Compass value but i could not find anything related to that.

https://developers.google.com/maps/documentation/ios/map

Maheta Dhaval K
  • 764
  • 6
  • 19

4 Answers4

6

Seems like there is no direct step for this functionality in Google Maps iOS SDK. You can possibly achieve the required effect by combining the below 2 functions:

1, Occasionally read the current bearing using locationManager:didUpdateHeading:. Check this post to see the usage

2, When you get a new bearing value, set the bearing using [mapView_ animateToBearing:x];

Community
  • 1
  • 1
tony m
  • 4,769
  • 1
  • 21
  • 28
2

By combining all the links in the above post, Here is an attempt to rotate GoogleMaps iOS SDK and it worked fine for me

First create a CLLocationManager

    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate=self;
    locationManager.desiredAccuracy=kCLLocationAccuracyBest;
    locationManager.distanceFilter=kCLDistanceFilterNone;
    [locationManager startUpdatingLocation];

    [locationManager startUpdatingHeading];

and use the CLLocationManager's startUpdatingHeading method to call the delegate method - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading whenever there is a change in heading. Now you can change rotate the map according to the heading using the following code.

- (void)locationManager:(CLLocationManager *)manager  didUpdateHeading:(CLHeading *)newHeading
{
    double heading = newHeading.trueHeading;
    double headingDegrees = (heading*M_PI/180);
    CLLocationDirection trueNorth = [newHeading trueHeading];
    [mapView_ animateToBearing:trueNorth];
}
geet Sebastian
  • 677
  • 6
  • 12
1

SWIFT 3.0

Need to set up location manager and call startUpdatingHeading:

class NavegacaoRotaViewController: UIViewController ,GMSMapViewDelegate,CLLocationManagerDelegate

...

self.locationManager = CLLocationManager()
self.locationManager.delegate = self
self.locationManager.startUpdatingHeading()

Then include the following delegate method and you should be able to extract the heading angle from newHeading:

func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
            googleMapsView.animate(toBearing: newHeading.trueHeading)
}

Obj-c

Need to set up location manager and call startUpdatingHeading:

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager startUpdatingHeading];

Then include the following delegate method and you should be able to extract the heading angle from newHeading:

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
  NSLog(@"Updated heading: %@", newHeading);
}
Ely Dantas
  • 705
  • 11
  • 23
  • How can we rotate the map back to default true North. I know if the compass is visible the user can press the compass and it will rotate the make to true north but how can it be done programmatically. – SwiftER Nov 10 '17 at 23:03
1

map rotation swift 5.0

 func intlizeLocationManager(){
    locationManager = CLLocationManager()
    handleArea.delegate = self
    handleArea.settings.myLocationButton = true
    locationManager?.delegate = self
    locationManager?.requestAlwaysAuthorization()
    locationManager?.desiredAccuracy = kCLLocationAccuracyBestForNavigation
    locationManager.distanceFilter = kCLDistanceFilterNone
    locationManager?.requestWhenInUseAuthorization()
    locationManager?.allowsBackgroundLocationUpdates = true
    locationManager?.startUpdatingLocation()
    locationManager.startMonitoringSignificantLocationChanges()
    locationManager.startUpdatingHeading()

}

 func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
    let head = newHeading.trueHeading
    map.animate(toBearing: head)
}
Imran Rasheed
  • 825
  • 10
  • 25