UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

How do i get finger position with my Mapkit Map ?

Forums > SwiftUI

Hi everyone,

I'm pretty new with Swift, and right now i'm using MapKit with a coordinator.

I was pretty satisfied until i had to retrieve where the user touched the map. My aim for the moment is only to draw like a line, a polygon on my map, when the user touches the map.

I followed Paul Hudson's videos (huge thanks to him for the well explained content) to make my MapView and my Coordinator, and another tutorial to draw over my map, which was using a regular controller. I tried to adapt the second to tutorial with my Coordinator.

I finally arrived to the point where i'm trying to override the function "touchesBegan" in my Coordinator like this :

       var points = [CLLocationCoordinate2D]() {
            didSet {
                print(points)
            }
        }

        override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
            mapViewTest.removeOverlays(mapViewTest.overlays)
            if let touch = touches.first {
                let coordinate = mapViewTest.convert(touch.location(in: mapViewTest), toCoordinateFrom: mapViewTest)
                points.append(coordinate)
            }
        }

But nothing happens when i use the simulator. Even if i just print something in my "touchesBegan" or "touchesMoved", i don't get anything in my console.

I don't really know what i am doing wrong, and how to do it properly. If you have any tips, i would be thankful. (Sorry if i made english mistakes !)

Regards, Samy

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.