swiftUI、Mapkitを使った地図の中心位置情報を取得したい
解決したいこと
iOS17.0~のswiftUI、Mapkitを使った地図の中心位置情報を取得したいです。
下図のように、MapReaderでMapを囲みタップした位置を取得するのではなく、
MapReader { reader in
Map()
.onTapGesture(perform: { screenLocation in
guard let location = reader.convert(screenLocation, from: .local) else { return }
print("tapped point: ", location)
})
}
タップせず、地図に表示されている中心値の緯度経度が知りたいです。
(現在地ではなく、地図を移動させた時も、その中心の緯度経度が知りたい。タップせず。)
自分で試したこと
@State private var position: MapCameraPosition = .userLocation(fallback: .automatic)
var location = position.camera?.centerCoodinate
上記のようにやって、locationにセンターの位置情報が入るかなーと思いきや現在位置しか入らなかった・・・。
困ってます。どなたか回答お願いいたします。
0 likes