I would like to allow the user of my app to pick a location in the map. The native map has a "drop pin" feature where you can locate something by dropping a pin. How can I do this in MapKit?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- How do you change the color of the dotted line on
- how do you prevent page scroll in textarea on mobi
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- Avoiding “Sorry, we have no imagery here” with Goo
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Custom Marker performance iOS, crash with result “
- Open iOS 11 Files app via URL Scheme or some other
- Google Map Gradient Polylines for Android?
There are multiple ways to drop a pin, and you don't specify which way to do it in your question. The first way is to do it programmatically, for that you can use what RedBlueThing wrote, except that you don't really need a custom class (depending on what version of iOS you are targetting). For iOS 4.0 and later you can use this snippet to programmatically drop a pin:
If you want to be able to drop a pin by for example long pressing on the actual mapView, it can be done like this:
If you want to enumerate all the annotations, just use the code in both snippets. This is how you log positions for all annotations:
You might also need to set MapView Delegate.
Then call its delegate,
viewForAnnotation
:You need to create an object that implements the MKAnnotation protocol and then add that object to the MKMapView:
Instantiate your delegate object and add it to the map:
The map will access the coordinate property on your AnnotationDelegate to find out where to put the pin on the map.
If you want to customize your annotation view you will need to implement the MKMapViewDelegate viewForAnnotation method on your Map View Controller:
If you would like to implement the pin drag functionality you can read about handling annotation touch events in the Apple OS Reference Library.
You can also check out this article on drag drop with mapkit which refers to a working sample library on GitHub. You can get the coordinates of the dragged annotation by checking the _coordinates member on the DDAnnotation object.
you can get touched location by ,jcesarmobile answer on get tapped coordinates with iphone mapkit and you can drop pin any where as bellow