Kodeco Forums

MapKit Tutorial: Getting Started

Learn how to use the MapKit framework to display real-world points of interest in your own apps.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/548-mapkit-tutorial-getting-started

Thanks for this update :slight_smile:

In the tutorial you forgot to add the code of the imageName property, which is present on the final project :

var imageName: String? {
    if discipline == "Sculpture" { return "Statue" }
    return "Flag"
}

I was wondering if it was a bad practice to return directly an UIImage? instead of its name, but I realized it allows the Artwork class to be compatible with MacOS since UIKit isn’t needed.
So instead I’ll use an Artowk_iOS extension, following the example of Porting Your iOS App to macOS tutorial.

I prefer returning an optional UIImage instead of an optional String, because of these lines of code in the setter of the annotation property of ArtworkMarkerView (or ArtworkView with image instead of glyphImage) :

if let imageName = artwork.imageName {
       glyphImage = UIImage(named: imageName)
 } 

If the imageName is nil, then glyphImage will not be set. But since the annotation are reused, you will keep the previous image, which will lead to weird behaviour. As a workaround, you can either have Artwork to return directly an optional UIImage or set glyphImage to nil before setting it.

you’re right on both points!

I accidentally dropped the imageName property when I added the glyphImage code.

And yes, images should default to nil.

I’ll update the update soon. Thanks!

Thanks a lot for this tutorial, you’re great!

1 Like

Great tutorial!

you just forgot to mention to change:
let identifier = “marker”
to:
let identifier = MKMapViewDefaultAnnotationViewReuseIdentifier
after creating the marker view, because you registered the view using that id on:
mapView.register(ArtworkMarkerView.self, forAnnotationViewWithReuseIdentifier: MKMapViewDefaultAnnotationViewReuseIdentifier)

and after “Images, Not Markers” you have to comment the view for annotation method as it is on the finished project

on the finished project you have the wrong Artwork.swift file, its not added to the project but its on the .zip and you renamed the var markerTintColor to pinTintColor

thanks!

after registering the default identifier, I say to “comment out the mapView(_:viewFor:) method” — it’s no longer needed.

you’re absolutely right about the final project! too much editing back and forth, I guess … I’ve uploaded a new zip file.

Great tutarial, thank you.,
Is there a option to avoid routing on Highways (Autobahn) or toll routes? I cant find any solution for this.

Hi rico: that’s a Maps app issue, so beyond the scope of my expertise.

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]