Scroll about halfway down, to āCalculating Routeā¦ā with MapKit. Itās older Swift, but Xcode will help you update it, or check the documentation for MKDirectionsRequest and MKRoute.
Oh sorry, you misunderstood me, I donāt wanna make route like in this example, I make route like in your example, and this great, but I want to āfunc mapItem()ā works when user tapped not on information button and the my button
If I create button like that:
let smallSquare = CGSize(width: 30, height: 30)
let button = UIButton(frame: CGRect(origin: CGPoint.zero, size: smallSquare))
button.setBackgroundImage(UIImage(named: ācarā), for: UIControlState())
button.addTarget(self, action: #selector(Artwork.mapItem), for: .touchUpInside)
view?.leftCalloutAccessoryView = button
how can i add it to your navigation method?
if you just want to use the left callout accessory view instead of the right one, you donāt need to addTarget; the calloutAccessoryControlTapped method will run when you tap the left button.
Hi! Great tutorial! I have an API that returns several locations and I am able to place and show them on the map without any issues. I would like to display the index number (+1) from my locations array of every location in a UIView that I created but canāt seem to figure out how to access the indexPath of my array when I select a pin. Can you please help with that? Still fairly new to programming and swift. Thanks
I think you need to store the index in each annotation. For Artwork, I added an index property, and added an index parameter to its init and fromJSON methods:
Follow instructions at the end of the tutorial, in the section about Info.plist item
Edit scheme: Options\Core Location: check Allow Location Simulation and select a Default Location.
Build and run; drag the map away from simulated user location, then tap the bar button. The first time, an alert will ask permission to use your location. After allowing, youāll have to tap the button a second time, to make the map move. But the next time you move away from the user location, then tap the button, the map will move back to the userās location, with the glowing blue dot. Apple says to ask permission as close as possible to when you need to use their location, but you could use the checkLocationAuthorizationStatus() method, as described in the tutorial, to get the permission out of the way as soon as the app loads.