↓これでどうでしょうか?
Map(position: $position, interactionModes: .all)
.onMapCameraChange(frequency: .onEnd, { mapCameraUpdateContext in
print("now center: ", mapCameraUpdateContext.region.center)
})
1Like
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にセンターの位置情報が入るかなーと思いきや現在位置しか入らなかった・・・。
困ってます。どなたか回答お願いいたします。