swiftuimapkitgesture

Does anyone have MapKit+LongPress working?


I am trying to get SwiftUI + MapKit + LongPress gesture working. When I add the map within the ContentView, it works great. I then add the .onLongPressGesture modifier to the map, and the panning/zooming stops working. Long press works though.

The code I am working on:

Map(coordinateRegion: $region, interactionModes: .all, showsUserLocation: true)
  .onLongPressGesture {
    // How do I get the location (Lat/Long) I am pressed on?
    print("onLongPressGesture")
  }

Also, is there a way to get the lat/long from the long press gesture?

Looking to make it work using SwiftUI only, without wrapping UIKit within a UIViewRepresentable.


Solution

  • Don't ask why but this seems to work:

        Map(coordinateRegion: $region, interactionModes: .all, showsUserLocation: true)
            .gesture(DragGesture())
            .onLongPressGesture {
                print("Here!")
            }