I am working on an app that displays certain markers based on a radius around your current location. The radius is between 100 - 5000 meters. I change the radius with an U
Here's a simpler solution for getting the bounds of a GMSCircle
.
It doesn't rely on MapKit and avoids the two calls that change the camera position (moveCamera
and animateToLocation
)
import GoogleMaps
extension GMSCircle {
func bounds () -> GMSCoordinateBounds {
func locationMinMax(_ positive : Bool) -> CLLocationCoordinate2D {
let sign: Double = positive ? 1 : -1
let dx = sign * self.radius / 6378000 * (180 / .pi)
let lat = position.latitude + dx
let lon = position.longitude + dx / cos(position.latitude * .pi / 180)
return CLLocationCoordinate2D(latitude: lat, longitude: lon)
}
return GMSCoordinateBounds(coordinate: locationMinMax(true),
coordinate: locationMinMax(false))
}
}
After adding this file to your project, all you have to do is:
let update = GMSCameraUpdate.fit(myCircle.bounds())
myMap.animate(with: update)
where myCircle
and myMap
are replaced by the actual circle and map.