# MapKit Tutorial: Getting Started

**URL:** <https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355>\
**Category:** 🎓 Courses & Articles\
**Created:** [March 4, 2016, 10:40am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355 "2016-03-04T10:40:20Z")\
**Posts on this page:** 20\
**Page:** 9

<div class="post-metadata">

**Author:** ![naveezodiac](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/naveezodiac/32/60020_2.png) [@naveezodiac](https://forums.kodeco.com/u/naveezodiac)\
**Post date:** [March 16, 2017, 5:23am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/164 "2017-03-16T05:23:20Z")

</div>

Thx. It works now. Had a problem with returning values. But took care of it.  
and BTW, your tutorial is awesome. Learned so much from this.  
Thx again.

---

<div class="post-metadata">

**Author:** ![dcmcvarish](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/dcmcvarish/32/71956_2.png) [@dcmcvarish](https://forums.kodeco.com/u/dcmcvarish)\
**Post date:** [April 22, 2017, 11:32am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/165 "2017-04-22T11:32:37Z")

</div>

Audrey:

Thanks for clear and useful tutorial. I would like to adapt it to an app showing World War I monuments in New Jersey but am unsure as to how to format the data and images (I’m new at this.) Any suggestions?

---

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [April 23, 2017, 12:32am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/166 "2017-04-23T00:32:47Z")

</div>

do you mean, the data isn’t already in a database, like my Honolulu Art?

if you store the data in the app itself, you don’t need to work with JSON; use the file manager or a property list: [Saving Data video course](https://videos.raywenderlich.com/courses/69-saving-data-in-ios/lessons/1)

do you want to make an iOS app version of [this page](http://www.worldwar1centennial.org/index.php/nj-wwi-related-locations.html)?

it seems they only provide addresses, so you’d need to use geocoding to get the latitude and longitude: [MapKit video course part 4](https://videos.raywenderlich.com/courses/17-mapkit-and-core-location/lessons/4)

for images, you could link to theirs, but if they move them, you’ll need to update your app; also, you probably need their permission before you make your app publicly available.

is it an option to contact them directly, and ask for their data?

---

<div class="post-metadata">

**Author:** ![paolo](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/paolo/32/102075_2.png) [@paolo](https://forums.kodeco.com/u/paolo)\
**Post date:** [May 14, 2017, 10:11am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/167 "2017-05-14T10:11:24Z")

</div>

Hi, thanks a lot for the tutorial , is very clary and easy.

I want to ask a question .

I need to open the same JSON file from WEB URL , for example :“[HTTP://localhost/xxxx.JSON](HTTP://localhost/xxxx.JSON)” , not in build path.

How I can do ?

Thank you very much for your answer.

---

<div class="post-metadata">

**Author:** ![samdecrock](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/samdecrock/32/66937_2.png) [@samdecrock](https://forums.kodeco.com/u/samdecrock)\
**Post date:** [May 14, 2017, 11:05am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/168 "2017-05-14T11:05:22Z")

</div>

If the delegate works like a table view delegate, why should you split up the creation of an MKPinAnnotationView.

This works too:

```
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    if let artwork = annotation as? Artwork {
        var artworkView = mapView.dequeueReusableAnnotationViewWithIdentifier("ArtworkView")
        artworkView.annotation = artwork
        artworkView.canShowCallout = true
        return artworkView
    }
    
    return nil
}

```

---

<div class="post-metadata">

**Author:** ![samdecrock](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/samdecrock/32/66937_2.png) [@samdecrock](https://forums.kodeco.com/u/samdecrock)\
**Post date:** [May 14, 2017, 11:30am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/169 "2017-05-14T11:30:17Z")

</div>

Ok, never mind.

If I don’t create the MKAnnotationView first and just dequeue it all the time, I won’t get the callout button.

---

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [May 15, 2017, 12:07am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/170 "2017-05-15T00:07:29Z")

</div>

hi Paolo: if your file is really local, you can use [`Data(contentsOf:)`](https://developer.apple.com/reference/foundation/nsdata/1413892-init); but if the file is on a remote server, you should use URLSession. You can start with [NSURLSession Tutorial](https://www.raywenderlich.com/110458/nsurlsession-tutorial-getting-started) - I’ve written an update for this, which should appear next month or so. Or look at our [URLSession video course](https://videos.raywenderlich.com/courses/67-networking-with-urlsession/lessons/1).

`Data(contentsOf:)` blocks the main thread, so you shouldn’t use it to get data from remote servers.

---

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [May 15, 2017, 12:08am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/171 "2017-05-15T00:08:40Z")

</div>

hi Sam: thanks for posting! I’m glad you figured it out 😄

---

<div class="post-metadata">

**Author:** ![paolo](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/paolo/32/102075_2.png) [@paolo](https://forums.kodeco.com/u/paolo)\
**Post date:** [May 15, 2017, 1:44pm UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/172 "2017-05-15T13:44:35Z")

</div>

i have try but is not simple, can you help me ?

var networks = Artwork  
func loadInitialData() {  
// 1

```
var url: URL!
url = URL(string: "https://10.6.68.141/node.json")

```

// let fileName = Bundle.main.path(forResource: “node”, ofType: “json”);

```
    do {
        
    
    data = try URL(contentsOf: url)

```

// data = try Data(contentsOf: URL(fileURLWithPath: fileName!), options: NSData.ReadingOptions(rawValue: 0))

```
} catch _ {
data = nil
}

// 2
var jsonObject: Any? = nil
if let data = data {
  do {
   jsonObject = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions(rawValue: 0))
  } catch _ {
    jsonObject = nil
  }
}

```

---

<div class="post-metadata">

**Author:** ![paolo](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/paolo/32/102075_2.png) [@paolo](https://forums.kodeco.com/u/paolo)\
**Post date:** [May 15, 2017, 2:20pm UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/173 "2017-05-15T14:20:53Z")

</div>

Hi, delete last post , I found the solution and it work.

Thank very much for your support.

---

<div class="post-metadata">

**Author:** ![paolo](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/paolo/32/102075_2.png) [@paolo](https://forums.kodeco.com/u/paolo)\
**Post date:** [May 16, 2017, 1:22pm UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/174 "2017-05-16T13:22:31Z")

</div>

Hi , sorry but in local work but I don’t find a solution with URLSession for remote JSON link .  
Here the code that working with local link . Can you help me ? very thanks

var networks = Artwork  
func loadInitialData() {  
// 1

```
var url: URL!
url = URL(string: "http://10.6.82.163/node.json")

var data: Data!

do {
        
data = try? Data(contentsOf: url)
   
    

} catch _ {
print("Error: (data: contentsOf: url)")
data = nil
}

// 2
var jsonObject: Any? = nil
if let data = data {
  do {
   jsonObject = try JSONSerialization.jsonObject(with: data)
  } catch _ {
    jsonObject = nil
  }

// 3
if let jsonObject = jsonObject as? [String: Any],
// 4
let jsonData = JSONValue.fromObject(jsonObject)?["data"]?.array {
  for artworkJSON in jsonData {
    if let artworkJSON = artworkJSON.array,
    // 5
    let artwork = Artwork.fromJSON(artworkJSON) {
      self.networks.append(artwork)
    }
  }
}

```

}

}  
}

---

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [May 17, 2017, 4:54am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/175 "2017-05-17T04:54:15Z")

</div>

Look at the sample project of [NSURLSession Tutorial](https://www.raywenderlich.com/110458/nsurlsession-tutorial-getting-started): `func searchBarSearchButtonClicked` and the `func updateSearchResults` that it calls.

You might also need to look at our [JSON tutorial](https://www.raywenderlich.com/150322/swift-json-tutorial-2), because your JSON data will probably be different from PublicArt.json

---

<div class="post-metadata">

**Author:** ![ebarojas](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ebarojas/32/70172_2.png) [@ebarojas](https://forums.kodeco.com/u/ebarojas)\
**Post date:** [July 13, 2017, 3:16pm UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/176 "2017-07-13T15:16:34Z")

</div>

Hi @audrey Where can I find the Xcode 8 version of this project? I don’t want to use Xcode 9 yet and am trying to follow the tutorial but am stuck at MKMarkerAnnotationView since that is not in Xcode 8.

Please advise. Thank you!

---

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [July 14, 2017, 12:28am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/177 "2017-07-14T00:28:05Z")

</div>

Hi Ernie: here’s a copy of the tutorial and projects from before this last update to Xcode 9 beta:

[MapKitTutorial\_Xcode8.zip](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/7/6/76394f8a378518a355d610cdeb05434c1b2da9c0.zip) (1.6 MB)

---

<div class="post-metadata">

**Author:** ![acaviarhap](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@acaviarhap](https://forums.kodeco.com/u/acaviarhap)\
**Post date:** [July 29, 2017, 12:48pm UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/178 "2017-07-29T12:48:25Z")

</div>

Hi Audrey - would you have any examples where MKMapviewdelegate methods are held in a separate swift file / class, so that map views in different view controllers can call the same methods? Or is this a stupid idea? best regards AC.

---

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [July 30, 2017, 11:33am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/179 "2017-07-30T11:33:18Z")

</div>

hi AC: the delegate methods are usually implemented in an extension of the view controller. I suppose you could create a delegate class — a singleton? — that all the view controllers access.

---

<div class="post-metadata">

**Author:** ![acaviarhap](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@acaviarhap](https://forums.kodeco.com/u/acaviarhap)\
**Post date:** [July 30, 2017, 1:04pm UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/180 "2017-07-30T13:04:13Z")

</div>

but I take it, it is not common to do so? The background to my question is this, If you have one app, multiple viewcontrollers with a mapview on each (for different purposes) I would need one ‘draw the map pin’-method for each mapview, right? Lazy as I am, I thought (with my limited experience) I could consolidate this into using one such method for all map views. But I have abandoned it for now 🙂 Thanks for your tutorial, I consult it many times. /AC

---

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [August 8, 2017, 12:03am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/181 "2017-08-08T00:03:32Z")

</div>

actually, it could work, to create a mapViewService class … setting up the map view doesn’t often interact with the host view controller’s outlets? making the view controller the mapView’s delegate is more convenient if the delegate methods have to get/set values of view controller properties. Otherwise, a separate class could work well, and reduce code duplication.

---

<div class="post-metadata">

**Author:** ![shah12007](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shah12007/32/58952_2.png) [@shah12007](https://forums.kodeco.com/u/shah12007)\
**Post date:** [September 13, 2017, 8:34am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/182 "2017-09-13T08:34:56Z")

</div>

Hello! Can you help me please. I add phone number in subtitles in annotation. How I can make when user tap on phone number starting call. Or when user tap on URL link safari open.

---

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [September 13, 2017, 10:38am UTC](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355/183 "2017-09-13T10:38:54Z")

</div>

sorry Nikita, this is beyond my expertise.

see if this helps:

> **[How to make tappable links in NSAttributedString - free Swift 5.4 example...](https://www.hackingwithswift.com/example-code/system/how-to-make-tappable-links-in-nsattributedstring)**
>
> Learn Swift coding for iOS with these free tutorials

you can create a UITextView for `view.detailCalloutAccessoryView` instead of a UILabel, then try Paul Hudson’s example.

the url for a phone number is “tel://” + the number, and you call `UIApplication.shared.open`

[Previous page](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355.md?page=8)

[Next page](https://forums.kodeco.com/t/mapkit-tutorial-getting-started/6355.md?page=10)
