'Google Map Swift SDK - how to combine fitbounds and center user location?
What I'm attempting to do is run fitbounds on a set of markers, which works perfectly. However, I would like to center the map based on the user's location while keeping all markers within the map view. But I haven't found a solution. Is it possible? below is my code currently use to fit bounds.
func focusMapToShowAllMarkers() {
var bounds = GMSCoordinateBounds()
for location in locationsArray
{
let latitude = location.position.latitude
let longitude = location.position.longitude
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude:latitude, longitude:longitude)
//marker.map = self.viewMap
bounds = bounds.includingCoordinate(marker.position)
}
//bounds = bounds.includingCoordinate(CLLocationCoordinate2D(latitude:latitude, longitude:longitude))
let update = GMSCameraUpdate.fit(bounds, withPadding: 10)
viewMap.animate(with:update)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
