Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: How to know the top right and bottom left coordinates of a google map

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

}
like image 225
Dani Avatar asked Jun 16 '16 14:06

Dani


Video Answer


2 Answers

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.

like image 175
Derek Soike Avatar answered Sep 24 '22 05:09

Derek Soike


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.

like image 29
noogui Avatar answered Sep 20 '22 05:09

noogui