5

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.

jdog
  • 10,351
  • 29
  • 90
  • 165

1 Answers1

14

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

Jordan
  • 551
  • 3
  • 11
  • hey jordan i need your help look at this question http://stackoverflow.com/q/19268080/1468406 please help if you have any idea. – Pratik B Oct 15 '13 at 05:52
  • Uber iOS app is using Google maps, how to do it in Google Maps. Confused. Another awesome feature in Uber, You can tap anywhere in the map (any coordinate), the map gets zoomed to the center but won't change it's coordinates. Unless you drag the map you can't change the coordinates of the map. Please help. Thanks a million in advance – Rajesh Feb 17 '15 at 08:20