7

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

}
Dani
  • 187
  • 2
  • 7

2 Answers2

12

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.

Community
  • 1
  • 1
Derek Soike
  • 11,238
  • 3
  • 79
  • 74
3

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.

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
  • Actually I need to get those GMSCoordinateBounds from the mapView or the camera. But I can't find how to get them. There's a function to create a camera with bounds, but I don't need to create a camera, I need to get the bounds of the existing camera! – Dani Jun 20 '16 at 13:48