11
I use google Maps SDK for iOS. I have markers on my map and want to set proper zoom so that markers are separate and also markers should be visible on screen all at once. I am able to do it.I have done using logic that if all markers are visible then zoom in. But the problem is that map camera is changing sharply. I tried a lot to animate this zoom but I failed to do to. I tried animateToCameraPosition, animateToZoom and UIView animation method.
- (BOOL)allCoordinatesVisibleWithLatitudes:(NSArray *)arrayOfLatitudes Longitudes:(NSArray *)arrayOfLongitudes
{
CLLocationCoordinate2D coordinate;
for(int i=0;i<arrayOfLatitudes.count;i++)
{
coordinate = CLLocationCoordinate2DMake([[arrayOfLatitudes objectAtIndex:i] floatValue], [[arrayOfLongitudes objectAtIndex:i] floatValue]);
if(![self.mapView.projection containsCoordinate:coordinate])
{
return NO;
}
}
return YES;
}
- (void)setZoomToHaveProperView
{
NSMutableArray * arrayOfLatitudes = [[NSMutableArray alloc] init];
NSMutableArray * arrayOfLongitudes = [[NSMutableArray alloc] init];
RS_SingleMatch * singleMatch = [[RS_SingleMatch alloc] init];
float zoom = 0.0;
// You may ignore this first for loop. it just takes coordinate of all markers in arrays.
for(int i=0;i<=self.userMatches.arrayOfMatches.count;i++)
{
if(i==self.userMatches.arrayOfMatches.count)
{
RS_Trip * userTrip = [[RS_Trip alloc] init];
[arrayOfLatitudes addObject:[NSNumber numberWithFloat:userTrip.fromLat]];
[arrayOfLongitudes addObject:[NSNumber numberWithFloat:userTrip.fromLon]];
if(self.segmentedControl.selectedSegmentIndex == 1)
{
[arrayOfLatitudes addObject:[NSNumber numberWithFloat:userTrip.toLat]];
[arrayOfLongitudes addObject:[NSNumber numberWithFloat:userTrip.toLon]];
}
}
else
{