Open3

x-code15にしないとMapkitチュートリアルができないのに気づいた!

JboyHashimotoJboyHashimoto

動画のMarkerは{}じゃなくて、()

かっこが違う???

import SwiftUI
import MapKit

extension CLLocationCoordinate2D {
    static let parking = CLLocationCoordinate2D(latitude: 42.354528, longitude: -71.068369)
}

struct ContentView: View {
    var body: some View {
        Map{
            // 動画は、{}に見えるが、()だった!
            Marker("Parking", coordinate: .parking)
        }
    }
}

#Preview {
    ContentView()
}

JboyHashimotoJboyHashimoto

Objectを重ねて表示できる

車のiconを地図上に表示してみる。

import SwiftUI
import MapKit

extension CLLocationCoordinate2D {
    static let parking = CLLocationCoordinate2D(latitude: 42.354528, longitude: -71.068369)
}

struct ContentView: View {
    var body: some View {
        Map{
            Annotation("Parking", coordinate: .parking) {
                ZStack {
                    RoundedRectangle(cornerRadius: 5)
                        .fill(.background)
                    RoundedRectangle(cornerRadius: 5)
                        .stroke(.secondary, lineWidth: 5)
                    Image(systemName: "car")
                        .padding(5)
                }
            }
            .annotationTitles(.hidden)
        }
    }
}

#Preview {
    ContentView()
}