Forward Geocoding: Using getCoordinates() function to create MKMapItem

Hello,

I have successfully used the getCoordinates() function provided by Apple Documentation to convert an address to coordinates. I created my own struct for a Pin that includes name, latitude, and longitude as properties.

I am able to add Markers to my map using these three properties. My problem is that I'd like to use these Markers to pull up further information, such as lookaround views. To use these API call functions, I need to provide an MKMapItem as an argument to the mapItem parameter.

MKLookAroundSceneRequest(mapItem: MKMapItem)

I'm having trouble using the MKMapItem documentation to understand how to make my own MKMapItems.

If I try using the autocomplete in XCode, I can get this:

MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: latitude, longitude: longitude)))

Is it possible to add a name when instantiating a new MKMapItem? From the documentation, it seems like name is a property of MKPlacemark, but I can't get this to work.

Should I alter the getCoordinates() function to return the entire placemark instead of just the coordinates?

Any guidance would be much appreciated! Thanks!

A friend helped me and wrote this custom initializer that accepts a name when creating a new MKMapItem.

extension MKMapItem {
    public convenience init(name: String? = nil, lat: Double, lon: Double) {
        let placemark = MKPlacemark(coordinate: .init(latitude: lat, longitude: lon))
        self.init(placemark: placemark)
        self.name = name
    }
}

Still looking for guidance on how to create MKMapItem that is suitable for use in MKLookAroundSceneRequest() function.

When I print the MKMapItem from a working Lookaround view:

<MKMapItem: 0x600003ecf800> {
    isCurrentLocation = 0;
    name = "503 Alger St";
    placemark = "503 Alger St, 503 Alger St, Detroit, MI  48202, United States @ <+42.38204680,-83.07368270> +/- 0.00m, region CLCircularRegion (identifier:'<+42.38204680,-83.07368270> radius 70.59', center:<+42.38204680,-83.07368270>, radius:70.59m)";
    timeZone = "America/Detroit (EST) offset -18000";
}

The MKMapItem's I have created look like this but do not work for Lookaround view:

    isCurrentLocation = 0;
    name = "503 ALGER ST DETROIT MI 48202-2163 USA";
    placemark = "503 ALGER ST DETROIT MI 48202-2163 USA @ <+42.38204680,-83.07368270> +/- 0.00m, region CLCircularRegion (identifier:'<+42.38204680,-83.07368270> radius 0.00', center:<+42.38204680,-83.07368270>, radius:0.00m)";
}

<MKMapItem: 0x600003e24400> {
    isCurrentLocation = 0;
    name = "2501 SHERIDAN ST, DETROIT, MI, 48214-1793";
    placemark = "2501 SHERIDAN ST, DETROIT, MI, 48214-1793 @ <+42.35993330,-83.00728570> +/- 0.00m, region CLCircularRegion (identifier:'<+42.35993330,-83.00728570> radius 0.00', center:<+42.35993330,-83.00728570>, radius:0.00m)";
    timeZone = "EST (GMT-5) offset -18000";
}

You can see I tried adding timeZone property to one, but that didn't work. I'm noticing that "radius:70.59m" vs "radius:0.00m" could be the factor I need to figure out to get this working. I wish there was a guide or additional documentation to help me understand how to use this framework! Thanks for any help :)

Forward Geocoding: Using getCoordinates() function to create MKMapItem
 
 
Q