How to set draggable Map pin - ios

I am developing an application in which I have included MapKit.
When first map is loaded at the time pin will be located at predefine place. And at that time drag-gable property of pin is set to NO.
Now I want to do this..
When user press button Edit it will allow user to drag pin. And when user drag pin and locate it at new place it will show user pin location name and lat long.

MKAnnotationView exposes the property draggable which can be set to enable dragging of each annotation added to map view.
The documentation for MKAnnotationView states:
If YES, the associated annotation object must also implement the setCoordinate: method. The default value of this property is NO.
Subclass MKAnnotationView and implement the setCoordinate method.
Then in your mapView:viewForAnnotation: method, set the draggable property to YES.

Related

In iOS UI Testing, how do I identify the MKUserLocation annotation?

I'm struggling to identify how I can tell that the MKMapView is showing the current user location pin in a UI Test. This is a MKUserLocation annotation (and I've created an MKAnnotationView to use an image for the pin instead of the blue spot.)
Debugging tells me that the MKUserLocation annotation instance has a title of "My Location". I was expecting that the following would work:
app.maps.element.otherElements["My Location"]
would return it but [that code].exists returns false. Printing debugDescription of otherElements lists a whole set of annotations on the map but not the User Location.
Is there a different type of XCUIElement that represents the pin/annotation/annotation view that I can check for?
Use accessibility labels to access your MKAnnotationView. In your code, retrieve your user location annotation and set an accessibility label for it:
yourAnnotation.accessibilityLabel = "labelYouWillUseToFindIt"
Then during your tests you can do:
app.maps.element.otherElements["labelYouWillUseToFindIt"]
Use print(app.debugDescription) to see if your annotation is visible and if not, force it to be accessible with:
yourAnnotation.isAccessibilityElement = true
You can read more about accessibility labels here

Hiding button in annotation callout Swift

I am wondering how I can hide and show a button in an annotation callout?
I set up my annotation view to have a left and a right button, each doing a separate task. The user can add an annotation by selecting a location from a table or long press.
I want the left button to be accessible and the right button to be hidden when the annotation is added via selection from table and the left button to be hidden the the right button to be accessible when the annotation is added via long press.
I have the buttons in the callout working but I can't figure how how to hide/show them. Any help is much appreciated!
Don't use a generic MapAnnotation object. Create a custom object that conforms to the MKAnnotation protocol and give it an Enum property that has a different value if it's added from your table or from a long press.
In your viewForAnnotation method, cast the annotation object to your custom type and check the property before deciding which callouts to add. (You'll need special-case code for the user location, as always.)

Disable all user interaction for MKMapView except for a given MKAnnotationView

I have a MKMapView and a few MKAnnotationViews on my map.
When a certain event happens, I would like to disable user interaction on my MKMapView but leave interaction on my MKAnnotationView available.
Ideally, it would be
self.mapView.userInteraction = NO;
self.myAnnotationView.userInteraction = YES;
Printing
[self.mapView recursiveDescription]
I have found that my annotation view is nested in MKNewAnnotationContainerView which doesn't have a publicly exposed property on Apple's class reference.
Any ideas?
On the mapView, set scrollEnabled, zoomEnabled, pitchEnabled, and rotateEnabled to NO and leave userInteractionEnabled as YES.
This way, the annotation views will still be enabled.
For pitchEnabled and rotateEnabled, you may want to check if those properties exist before setting them (eg. check if the map view respondsToSelector:#selector(setPitchEnabled), etc.) since they were added in iOS 7.

Annotations, Annotations, Annotations

So `MKAnnotation's. Fun stuff.
My questions:
What's the difference between an annotation's title and its subtitle and how does that affect the visual component of the annotation?
What's the difference between a MKPinAnnotationView and a MKAnnotationView?
Are there different types of map annotations in iOS apart from pins?
Title is main heading of your pin.
The subtitle is actually displaying the address/(common info) of the dropped pin.You can store other deeply information of related to title that is puted on pin.
MKAnnotation is a protocol you need to adopt if you wish to show your object on a MKMapView. The coordinate property tells MKMapView where to place it. title and subtitle properties are optional but if you wish to show a callout view you are expected to implement title at a minimum.
MKAnnotationView visually presents the MKAnnotation on the MKMapView. The image property can be set to determine what to show for the annotation. However you can subclass it and implement drawRect: yourself.
MKPinAnnotationView is a subclass of MKAnnotationView that uses a Pin graphic as the image property. You can set the pin color and drop animation.
Don't forget about the leftCalloutAccessoryView and the rightCalloutAccessoryView properties of MKAnnotationView that can be used to customize the callout view.
The title and subtitle are displayed when a pin is selected on the map. The subtitle simply falls below the title.
MKPinAnnotationView is simply an specialized form of MKAnnotationView that knows how to draw a pin (and a shadow) and also allows setting the pin color. It's the only built-in annotation view with an image, you have to make your own if you want something different (but it's very easy to do).

How to create custom annotation and callout bubble in iphone?

I want to create a customized annotation and callout bubble on MKMapView. I need to use a customized view rather than default annotation pin and annotaion view(which is limited to show only title and a single line description). When user tap on an annotation, I would like to display more information on the callout bubble.
I passed by this control but I haven't used it:
http://cocoacontrols.com/platforms/ios/controls/custom-callout
I've found some pretty good controls at that site.

Resources