Displaying two sets of GPS Coordinates on a map

I am trying to display two sets GPS Coordinates on a map, one being user’s current location and the other being coordinates input by the user. The code below has been copied from a reliable source but does not work for me. I am doing this in Playgrounds on an iPad where one can turn on permissions. I have turned on Core Location - When In Use. The map displays and has responded to the user inputs although not centered?

Obviously I am doing something wrong and would truely appreciate some advice here.

Another question I have is regarding internet access while using MapKit and CoreLocationUI. If internet is required is there a way of pre-loading before use?


import MapKit

import CoreLocationUI

var lat = -27.907625

var long = 152.680835



struct ContentView: View {

    @State private var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: (lat), longitude: (long)), span: MKCoordinateSpan(latitudeDelta: 0.00001, longitudeDelta: 0.00001))

    var body: some View {

        Map(coordinateRegion: $region, showsUserLocation: true, userTrackingMode: .constant(.follow))

            .frame(width: 400, height: 800)

    }

}

Found this is working for me except for displaying the user’s location.

Can someone tell me what I am doing wrong please 🙏

Positions View


import MapKit

struct Positions: Identifiable {

    let id = UUID()

    let name: String

    let latitude: Double

    let longitude: Double

    var coordinate: CLLocationCoordinate2D {

        CLLocationCoordinate2D(latitude: latitude, longitude: longitude)

    }

}

Map View


import MapKit

let thisCardPositionLatitude = -27.907625

let thisCardPositionLongitude = 152.680835

let nextCardPositionLatitude = -27.908190

let nextCardPositionLongitude = 152.679676



    struct MapView: View {

        @State private var region = MKCoordinateRegion(

            center: CLLocationCoordinate2D(

                latitude: thisCardPositionLatitude,

                longitude: thisCardPositionLongitude),

            span: MKCoordinateSpan(

                latitudeDelta: 0.00001,

                longitudeDelta: 0.00001)

        )

        private let places = [

            Positions(name: "This Card Position", latitude: thisCardPositionLatitude, longitude: thisCardPositionLongitude),

            Positions(name: "Next Card Position", latitude: nextCardPositionLatitude, longitude: nextCardPositionLongitude)

        ]

        var body: some View {

            Map(coordinateRegion: $region,

                showsUserLocation: true,

                userTrackingMode: .constant(.follow),

                annotationItems: places){ place in

                MapMarker(coordinate: place.coordinate,tint: Color.accentColor)

            }

                .edgesIgnoringSafeArea(.all)

        }

    }

    struct MapView_Previews: PreviewProvider {

        static var previews: some View {

            MapView()

        }

    }

EDIT: Working except for User’s Location (See below and ignore above)

Displaying two sets of GPS Coordinates on a map
 
 
Q