I need to know the top right and bottom left coordinate in a google map each time the camera is moved. The API gives me the center point of the camera. Is there a way to get what I want with the API or with some algorithm knowing the center point(target), zoom and bearing?
func mapView(mapView: GMSMapView, didChangeCameraPosition position: GMSCameraPosition) {
position.target
position.zoom
position.bearing
}
Swift 3
Use GMSProjection's visibleRegion method.
let projection = mapView.projection.visibleRegion()
let topLeftCorner: CLLocationCoordinate2D = projection.farLeft
let topRightCorner: CLLocationCoordinate2D = projection.farRight
let bottomLeftCorner: CLLocationCoordinate2D = projection.nearLeft
let bottomRightCorner: CLLocationCoordinate2D = projection.nearRight
Take a look at this question too.
How to know the top right and bottom left coordinates of a google map
Found this on iOs Maps Reference
GMSCoordinateBounds
represents a rectangular bounding box on the Earth's surface. It has the northEast and southWest properties of the bounding box.
- (id) initWithCoordinate: (CLLocationCoordinate2D) coord1 coordinate: (CLLocationCoordinate2D) coord2 Inits the northEast and southWest bounds corresponding to the rectangular region defined by the two corners. It is ambiguous whether the longitude of the box extends from coord1 to coord2 or vice-versa;
Check this Github repo for additional info on how to use it in your code.
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