user3766930
user3766930

Reputation: 5829

how can I fetch the longitude and latitude from a specific point on my mapview in swift?

I have a MKMapView in my app and currently I'm fetching the center point of this map by using:

longitude = mapView.centerCoordinate.longitude
latitude = mapView.centerCoordinate.latitude

but now instead of taking the center point of the map I want to take a specific point that is 100px below the top edge of my mapview. So normally I would use something like:

longitude = mapView.centerCoordinate.longitude
latitude = mapView.(centerCoordinate+100px).latitude

But that's not how that works apparently. Is there any way of fetching a specific point from mkmapview?

Upvotes: 0

Views: 49

Answers (2)

Code Different
Code Different

Reputation: 93141

Try this:

let frame = mapView.frame
let myPoint = CGPointMake(frame.midX, 100)
let myCoordinate = mapView.convertPoint(myPoint, toCoordinateFromView: mapView)

let annotation = MKPointAnnotation()
annotation.coordinate = myCoordinate
annotation.title = "My Point"

mapView.addAnnotation(annotation)

Upvotes: 1

Ben M.
Ben M.

Reputation: 39

Used the the MapKit method:

convertPoint:toCoordinateFromView:

Upvotes: 0

Related Questions