Annotations, Annotations, Annotations - ios

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).

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

Custom marker with server imagen in mapkit swift

Its posible set a custom marker with images loaded by server in mapview iOS swift? I jus found customs marker with local images
By marker, I'm assuming you are referring to and utilizing a MKAnnotationView (which is what Apple's pin views subclass from).
MKAnnotationView has an .image property, which you could set to any UIImage. You'd have to download the image first from server, then assign it to the annotation view.
It doesn't look like there is a way to link the MKAnnotationView's image property directly to a remote URL without defining that behavior for yourself (and perhaps subclassing drawing code).

How to set draggable Map pin

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.

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.

iPhone MapKit: Accessibility of Annotations

does anybody know how it is possible to add an accessibility label to a map annotation? I've tried adding it to the MKAnnotationView and the MKAnnotation but neither works. VoiceOver always only reads "pin" when an annotation is selected, while the original Maps application features the correct title when selecting an annotation.
Thanks and best regards,
Chris
In your -mapView:viewForAnnotation: set the accessibilityValue of your returned MKAnnotationView object.

Resources