Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(iPhone) how to implement draggable pins using OS 4.0 MapKit?

Can anyone provide any sample code/instructions for implementing draggable pins in OS 4.0 using the MapKit framework?

like image 500
WoodenKitty Avatar asked Jul 07 '10 03:07

WoodenKitty


People also ask

What are pins in Apple Maps?

Pins are essentially locations in Apple Maps that you mark yourself. Before you learn how to rename pins in Apple Maps, it’s useful to do a quick rundown on what they are (and what they aren’t). Open up Maps on your iPhone or iPad. Then, just tap and hold on a location.

Can I rename pins in Apple Maps?

While Apple Maps supports saved pins and label renaming, it isn’t the most intuitive thing to find. Pins are, of course, a useful way to save locations to your Favorites or a collection. But that usefulness only extends as far as your Maps organization goes. So here’s how to rename a pin in Maps. What are pins in Apple Maps?

How to add a marked location to favorites on Apple Maps?

Here’s how. Drop a pin in Apple Maps. Tap on the pin to bring up the options pane. Swipe up on this menu to see more options. Tap on Add to Favorites. Now, the next time you open a Maps window, the pin will be there. Near the Favorites tab, click on See All. Tap the “i” icon next to your Marked Location.

How do you mark a location on Google Maps on iPhone?

Open up Maps on your iPhone or iPad. Then, just tap and hold on a location. If there’s no business or point of interest there, you should see a pin appear with the name “Marked Location.” Not in the right place? Just tap and drag it to a new location. Note that you can only have one pin at a time.


2 Answers

Sure thing buddy (yes I'm talking to myself),

In your custom annotation add:

@property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate; 

This satisfies the requirement of implementing setCoordinate, as mentioned inhttp://developer.apple.com/iphone/library/documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html#//apple_ref/occ/instp/MKAnnotationView/draggable

In your MapView delegate add:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState 
{
//..Whatever you want to happen when the dragging starts or stops
}

and in your AnnotationView set draggable to true, so for example:

customAnnotationView.draggable      = YES;

I think that was everything that I did to get it working. Tell me if you have troubles.

like image 60
WoodenKitty Avatar answered Oct 23 '22 06:10

WoodenKitty


Check out MapKitDragAndDrop by Ching-Lang Huang and the author's accompanying blog post.

like image 33
Joost Schuur Avatar answered Oct 23 '22 08:10

Joost Schuur