Reputation: 1
I am learning to develop for iOS. I am using the Google Maps API for iOS to do a map. I've putted in my project a view that I've putted in my inspector element like GMSMapView.
In my code I put this code below:
- (void) setMapView:(GMSMapView *)mapView {
if (!mapView) {
mapView = [[GMSMapView alloc] initWithFrame:mapView.bounds];
}
googleMap = mapView;
}
The map works but I want to set up my camera on this map. On the viewDidLoad
function I`ve putted this code below:
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
longitude:151.2086
zoom:12];
self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
but the Google Maps just load this map on London I don't know why. Ths coordinates its from Sidney. I have tried googleMap = [GMSMapView mapWithFrame:CGRectZero camera:camera];
but don't works too.
Anybody can help me?
Upvotes: 0
Views: 365
Reputation: 11
I had the same problem. You can fix it by animating to the camera position once the Map has been allocated. I added a delay before animating to the new camera position. This works.
- (void)viewDidLoad
{
self.mapView = [[GMSMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; // Any Frame
double delayInSeconds = 0.2;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
longitude:151.2086
zoom:12];
[self.mapView animateToCameraPosition:camera];
});
}
Upvotes: 1