How to show my location and pin in map correctly on Swift?
cllocation, mapkit, swift
Solution
To display location on map using latitude and longitude.
var latDelta:CLLocationDegrees = 0.01
var longDelta:CLLocationDegrees = 0.01
var theSpan:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
var pointLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(your latitude, your longitude)
var region:MKCoordinateRegion = MKCoordinateRegionMake(pointLocation, theSpan)
mapView.setRegion(region, animated: true)
var pinLocation : CLLocationCoordinate2D = CLLocationCoordinate2DMake(your latitude, your longitude)
var objectAnnotation = MKPointAnnotation()
objectAnnotation.coordinate = pinLocation
objectAnnotation.title = your title
self.mapView.addAnnotation(objectAnnotation)
Problem
I'm trying sshow my location in app Swift but this not show anything, the map is all blue.. My code is this form a tutorial on internet: ``` var latitude:CLLocationDegrees = location.location.coordinate.latitude var longitude:CLLocationDegrees = location.location.coordinate.longitude var homeLati: CLLocationDegrees = 40.01540192 var homeLong: CLLocationDegrees = 20.87901079 var latDelta:CLLocationDegrees = 0.01 var longDelta:CLLocationDegrees = 0.01 var span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta) var myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude) var region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span) self.mapKit.setRegion(region, animated: true) self.mapKit.showsUserLocation = true ///Red Pin var myHomePin = MKPointAnnotation() myHomePin.coordinate = myHome myHomePin.title = "Home" myHomePin.subtitle = "Bogdan's home" self.mapKit.addAnnotation(myHomePin) ``` I have imported corresponding configuration in .split.. What is bad on this code? Thanks!