I am using Google Map service GMSMapview in my iOS Application. In that I have two CLLocationCoordinates. One is Current Location and other is Destination Location. I am trying to fit the map within those two places.
But the camera position is not set within those two points. I tried with the following code,
CLLocationCoordinate2D start = CLLocationCoordinate2DMake(newLoc.coordinate.latitude, newLoc.coordinate.longitude);
CLLocationCoordinate2D end = CLLocationCoordinate2DMake(_retailerVO.R_Latitude, _retailerVO.R_Longitude);
GMSCoordinateBounds *gBounds =
[[GMSCoordinateBounds alloc] initWithCoordinate:start coordinate:end];
GMSCameraPosition *gCamera = [mapView_ cameraForBounds:gBounds insets:UIEdgeInsetsZero];
mapView_.camera = gCamera;
Is there any way to achieve what I am looking for? All suggestions are appreciated.
In Swift
let bounds = GMSCoordinateBounds(coordinate: sourcePosition, coordinate: endPosition)
let camera: GMSCameraUpdate = GMSCameraUpdate.fit(bounds)
// let cameraWithPadding: GMSCameraUpdate = GMSCameraUpdate.fit(bounds, withPadding: 100.0) (will put inset the bounding box from the view's edge)
self.mapView.animate(with: camera)
Add padding with bounds, it works for me, hope it helps you,
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:start coordinate:end];
[self.viewMapView animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds withPadding:100.0f]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With