I'm trying to show a map with two markers with longitudes and latitudes that are retrieved from API.
the function that gets the longitudes and latitudes is called in Viewdidload
override func viewDidLoad() {
super.viewDidLoad()
getCurrent()
also the code to show the map with markers in viewdidload
so my full code looks something like this:
var longFamily = ""
let latFamily = ""
var latShop = ""
var longShop = ""
override func viewDidLoad() {
super.viewDidLoad()
getCurrent()
let coordinate₀ = CLLocation(latitude: CLLocationDegrees(Int(latFamily)!), longitude: CLLocationDegrees(Int(longFamily)!))
let coordinate₁ = CLLocation(latitude: (Int(latFamily)!, longitude: (Int(longFamily)!))
let distanceInMeters = coordinate₀.distance(from: coordinate₁) // result is in meters
let floatDistance = Float(distanceInMeters)
// get two markers with shop and client locations
map.delegate = self
// 2.
let sourceLocation = CLLocationCoordinate2D(latitude: (Int(latFamily)!, longitude: (Int(longFamily)!)
let destinationLocation = CLLocationCoordinate2D(latitude: (Int(latShop)!, longitude: (Int(latShop)!)
I know there is something I have to do to get the data before the map loads but not sure where. I'd appreciate your help
GetCurrent function calls API :
Alamofire.request(url!, method: .get, parameters: param,encoding: URLEncoding.default, headers: headers).responseJSON { response in
if let value: AnyObject = response.result.value as AnyObject? {
//Handle the results as JSON
let data = JSON(value)
self.LongShop = data["shopLong"]
// this is for family locations too