0

I am trying to do a slow flyover in my application using google maps SDK for iOS.

My current setup looks like this:

-(void)viewDidLoad
{

[super viewDidLoad];

locationManager = [[CLLocationManager alloc]init];

locationManager.delegate = self;


locationManager.distanceFilter = kCLDistanceFilterNone;


locationManager.desiredAccuracy = kCLLocationAccuracyBest;


[locationManager startUpdatingLocation];
[locationManager startUpdatingHeading];


CLLocation *location = [locationManager location];
CLHeading *heading = [locationManager heading];

CLLocationCoordinate2D coordinate = [location coordinate];
CLLocationDirection direction = [heading trueHeading];

//double latitude = coordinate.latitude;
//double longitude = coordinate.longitude;
//double deviceHeading = (direction*M_PI/180);
//NSLog (@"my longitude :%f",deviceHeading);

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:40.7080 longitude:-74.0103 zoom:17 bearing:50 viewingAngle:90];
myMapView.myLocationEnabled = YES;
myMapView.settings.scrollGestures = NO;
myMapView.settings.zoomGestures = NO;
myMapView.settings.tiltGestures = NO;

NSBundle *mainBundle = [NSBundle mainBundle];
NSURL *styleUrl = [mainBundle URLForResource:@"GoogleMapsStyle" withExtension:@"json"];
NSError *error;

[myMapView animateToCameraPosition:camera];


// Set the map style by passing the URL for style.json.
GMSMapStyle *style = [GMSMapStyle styleWithContentsOfFileURL:styleUrl error:&error];

if (!style) {
    NSLog(@"The style definition could not be loaded: %@", error);
}

myMapView.mapStyle = style;

[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat: 30] forKey:kCATransactionAnimationDuration];
GMSCameraPosition *camera2 = [GMSCameraPosition cameraWithLatitude: 40.9234 longitude: -74.3456 zoom: 17];
[myMapView animateToCameraPosition: camera2];
[CATransaction commit];

}

I found the CATransaction here:

Controlling Animation Duration in Google Maps for iOS

However, when I load my view, the map is blank for the duration of the CATransaction, and then the map loads at the camera2 location. Is there a way to fix this or a better workaround?

Thanks

Community
  • 1
  • 1

1 Answers1

0

Given code is almost correct but one line need to be remove:

[myMapView animateToCameraPosition: camera2];

Because of this line when the CATransaction complete first map set to camera position because this line of code:

[myMapView animateToCameraPosition:camera];

But when map camera set to camera2 then GMSCamera will set to camera2.