SwiftUI Tutorial (Combining Views) - Map Pin missing

Working through the "Combining Views" (first) tutorial on SwiftUI, I notice that the images and previews in the tutorial show a pin on the map for the specified location. My app doesn't have that.


I double checked the code in the download and I can't see any difference... except that my lat/long are specified as (latitude: 34.011286, longitude: -116.166868) and the download code has (latitude: 34.011_286, longitude: -116.166_868)...


Is this just a tutoirial glitch? (That the pin doesn't appear...)

Or a documentation error? (It isn't supposed to appear...)


Given that it looks useful, how difficult would it be to add the pin?


Thanks in advance...

Replies

//
// MapView.swift
// Landmark
//
// Created by Abenx on 2020/6/26.
//

import SwiftUI
import MapKit

#if !os(macOS)
struct MapView: UIViewRepresentable {
  var coordinate: CLLocationCoordinate2D

  func makeUIView(context: Context) -> MKMapView {
    MKMapView(frame: .zero)
  }
   
  func updateUIView( uiView: MKMapView, context: Context) {
    self.updateView(uiView, context: context)
  }
}
#else
struct MapView: NSViewRepresentable {
  var coordinate: CLLocationCoordinate2D

  func makeNSView(context: Context) -> MKMapView {
    MKMapView(frame: .zero)
  }
   
  func updateNSView(
nsView: MKMapView, context: Context) {
    self.updateView(nsView, context: context)
  }
}
#endif

extension MapView {
  func updateView( uiView: MKMapView, context: Context) {
    let span = MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01)
    let region = MKCoordinateRegion(center: coordinate, span: span)
    let annotation = MKPointAnnotation()
    annotation.coordinate = coordinate
     
    uiView.setRegion(region, animated: true)
    uiView.addAnnotation(annotation)
  }
}
   

struct MapView
Previews: PreviewProvider {
  static var previews: some View {
    MapView(coordinate: CLLocationCoordinate2D(
          latitude: 39.910358, longitude: 116.469841))
  }
}