Naveed Rafi
Naveed Rafi

Reputation: 2643

Is there any way to get the lat long of MKMapView of touch position - iPhone SDK

How to get the latitude and longitude of touch position on map view?

I want to drop a pin where user touches just like google's javascript API does.

Is it possible in iphone SDK? Tutorial would be a great help.

Upvotes: 2

Views: 2499

Answers (2)

Tommy
Tommy

Reputation: 100652

MKMapView has a method, - (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view that can be used to get the longitude and latitude that any specified point would fall on.

To get the touch position, if you're fine with limiting yourself to iOS 3.2 and above, by far the easiest thing to do is to add a UITapGestureRecognizer to the relevant MKMapView.

Upvotes: 3

TeAmEr
TeAmEr

Reputation: 4773

assuming the current lan/long is the center of the screen ...
know the distance between the touch position and the center of the screen + know each pixel how many hours/degrees and some simple calculation you will get the lat/long of the touch position you might get the degrees/hours per pixel from the zoom level maybe ?

am not an iphone guy , but this is an idea that might help :p

Upvotes: -1

Related Questions