Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fit bounds of GMSCircle with google maps SDK to completely show on map?

I want to show completely GMSCircle on MapView but radius of circle is dynamically changed. When radius is changed then MapView will be automatically adjust to view the complete circle on map to show all marker.

In Swift language, I have found a solution which may be helpful for me as given here: Change Camera Zoom based on Radius Google Maps iOS SDK

But I have to implement this in Objective-c and in Objective-c we didn't have bound property for GMSCircle.

Thanks in Advance,Please guide me.

like image 463
Aashish1aug Avatar asked Sep 08 '25 12:09

Aashish1aug


1 Answers

you have to set zoom level according to your radius

 // SET ZOOM LEVEL
    int zoomLevel = 11;
    double radius = raduismeter+ raduismeter / 2;
    double scale = radius / 500;
    zoomLevel = (int) (16 - log(scale) / log(2));
    zoomLevel++;

you have to set and calculate zoom level according to your need. Than you have to set radius circle

  GMSCircle *geoFenceCircle = [[GMSCircle alloc] init];
            geoFenceCircle.position =PinDropCoordinates;
            geoFenceCircle.strokeWidth = 0.5;
            geoFenceCircle.strokeColor = [UIColor redColor];        
            NSLog(@"%@",geoFenceCircle);
            geoFenceCircle.radius =5000.00;
            geoFenceCircle.map = self.mapView;

After setting circle you have to animate your Camera accordingly.

    [CATransaction begin];
        [CATransaction setValue:[NSNumber numberWithFloat:3] forKey:kCATransactionAnimationDuration];
        GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:PinDropCoordinates.latitude
                                                                longitude:PinDropCoordinates.longitude zoom:zoomLevel];
        [self.mapView animateToCameraPosition: camera];


        [CATransaction commit];
like image 79
Hasham Avatar answered Sep 10 '25 01:09

Hasham