How to get current user's location and add a Marker in Apple Maps in Swift 5?
ฝัง
- เผยแพร่เมื่อ 8 ก.พ. 2025
- Maps Series: Tutorial 3 📝
Tutorial 1 Link: • How to get current use...
Tutorial 2 Link: • How to use Places API ...
In this tutorial we'll see how to capture the current user's location add a Marker in Apple Maps in your Swift Project.This tutorial is the third in the series of implementing various types of Maps in Swift, so make sure you have subscribed 👆to our channel and you have hit the notification button 🔔
📌Updating info.plist file with Privacy settings for Location from 01:06
📌Adding Apple Map from 02:44
📌Adding CLLocationManagerDelegate from 03:31
📌Adding and Configuring Location Manager from 03:44
📌Adding Location Manager didupdatelocations from 06:09
📌Adding a Span MKCoordinateSpan from 09:19
📌Adding a Region MKCoordinateRegion from 11:29
📌Adding Map Annotation MKPointAnnotation from 12:39
📌Adding the locationManagerDidChangeAuthorization stub from 14:41
📌Demo, Showing a Apple Map with the current user's location and Map Annotation 18:30
We upload new videos every week!
Please reach out to me on the comments section if you have any doubts on this topic. Also, please Like & Subscribe the Channel and help us being part of your journey to learn Swift. Cheers until the next video!
#LocationManager#AppleMaps #Annotation #Swift
Hi... !! this tutorial is very helpful for me ... thanks for the tutorial ...
You are welcome!
Hi. You're doing great job. It will be helpful if you make videos about Core Animation. Hope you will cover some advance topics in upcoming days.
Thank you for your support! We will get there soon!
2ndly I want something like changing the icon of the pin in the apple map kit ... where as we can change the pin easily in the google maps ... can we change the pin icon (marker) in the Apple Maps ...? if yes plz comment
Yes you can. Below is the code for that:
FIRST: Set the delegate of the MapView to Self in viewdidload()
myMap.delegate = self
SECOND: Add MKMapViewDelegate to the Class
THIRD: Copy these lines of code to your Class. The Pin will change itself to a black circle dot.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if !(annotation is MKPointAnnotation) {
return nil
}
let annotationIdentifier = "AnyName"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier)
if annotationView == nil {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
annotationView!.canShowCallout = true
}
else {
annotationView!.annotation = annotation
}
let pinImage = UIImage(systemName: "circle.fill")
annotationView!.image = pinImage
return annotationView
}
@@RDLabswithRohant that will be great ... thanks
Do you know how to drop marker and get the user to describe what it is as a user on the app?
Hello James, One must use the PlacesAPI for this to happen. This calls for me to do a video on this subject