Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone: ubercab aka (uber) map coordinate

Can anyone describe how to get the map coordinate of a MKMapView by its position on center of screen? Check out Uber app (its free). They have a pin statically located in the middle of the screen and you drag the map but the pin stays there. The middle of the screen is they find your location (very very quickly) showing you the address you are close to.

like image 674
jdog Avatar asked Mar 02 '11 06:03

jdog


1 Answers

Heyo! I'm the mobile Engineer at Uber (you asked for some Uber help I assume :)) The trick is to place the pin, which is actually a UIImage, at the center of the map. The pin is on top of the map and is not an annotation. Then, whenever you get the regionDidChangeAnimated callback, you get the coordinate of the center of the map using this:

CLLocationCoordinate2D center = m_mapView.centerCoordinate;
CLLocation *location = [[[CLLocation alloc] initWithLatitude:center.latitude longitude:center.longitude] autorelease];

Ideally, you want the bottom part of the pin to point exactly at the center of the map view.

Hope this helps, Jordan

like image 69
Jordan Avatar answered Oct 21 '22 12:10

Jordan