The onTapGesture that returns a point is deprecated and only return screen coord.
So my question is how to take the x,y and get Lat/Long
Multiline
VStack {
Map()
// .onTapGesture {
// print("onTapGesture")
// }
// .onTapGesture(perform: {
// print ("onTapperform")
// })
.onTapGesture(perform: { pt in
print(pt)
})
BlockQuote
The current version I could add MKMapViewDelegate to my MapView
Multiline
@objc func handleTap(sender: UITapGestureRecognizer) {
guard sender.state == .ended else { return }
let locationInView = sender.location(in: parent.vm.mapView)
let tappedCoordinate = parent.vm.mapView.convert(locationInView, toCoordinateFrom: parent.vm.mapView)
}
BlockQuote
Can you provide me the iOS17/Xcode 15?
Post
Replies
Boosts
Views
Activity
I put together a little "hello MapKit" application to try with.
The idea is click the "Place A Pin" button, then the next spot, on them map clicked, a pin should appear.
My issue is HOW TO convert the X/Y position of the screen to Lat/Lon potions for CLLocation object.
Any body know how to do this?
Here is the GITHub Repo
https://github.com/tomha2014/LearnMapKitiOS17
Thanks
I was wondering if anybody has a solution? I just got my local data to sync with iCloud, that was fun and easy.
At first time startup I have to start and stop then restart it so see the data stored in iCloud, or add a record.
My data model is very simple
@Model
final class Person{
var name: String = ""
var age: Int = 0
init( name: String, age: Int) {
self.name = name
self.age = age
}
}
FYI: I asked the same question.
https://developer.apple.com/forums/thread/732003
Then I used one of my TSI about the question, I was told to open a defect/feature request. So I did.
I've not heard back.
There is a way using UIViewRepresentable and Tab Gestures that seem to work but it's a hack in my opinion.
Good Luck, if you figure it out please share :)
Apple answer my TSI and it worked :)
You need to wrap map with MapReader
here is a simple example:
`
MapReader{ reader in
Map(
position: $cameraProsition,
interactionModes: .all
)
{}
.onTapGesture(perform: { screenCoord in
pinLocation = reader.convert(screenCoord, from: .local)
})`
Here is my learning project:
https://github.com/tomha2014/LearnMapKitiOS17.git
I just figured out a little about MapReader
https://github.com/tomha2014/LearnMapKitiOS17.git
wrap map with MapReader
MapReader{ reader in
Map(){}
}
I got a reply. Use MapReader
Here is my example:
https://github.com/tomha2014/LearnMapKitiOS17.git
Now I'm trying to draw polylines
MapReader{ reader in Map() .onTapGesture(perform: { screenCoord in pinLocation = reader.convert(screenCoord, from: .local) })