0

I have been working in google poly line functionality. I have initialised the URL and I have used alamofire request. Everything with the URL is working fine but I could not draw the line and it was stating like invalid URL.

I have attached the code which I have tried.

let urlString = "https://maps.googleapis.com/maps/api/directions/json?origin=\(pickupcordinates)&destination=\(dropCoordinates)&mode=driving&key=AIzaSyDJUX9uBiZivQGlAu1KTUC1kcmaiAnI270"

Alamofire.request(urlString,method: .get, parameters: nil,encoding: JSONEncoding.default, headers: nil).responseJSON {
    response in
    switch response.result {
    case .success:
        print(response)
        break
    case .failure(let error):

        print(error)
    }
}

invalidURL(url: "https://maps.googleapis.com/maps/api/directions/json?origin=13.03589205752495,80.25411217280107&destination=13.0277895999, 80.22673778239999&mode=driving&key=AIzaSyDJUX9uBiZivQGlAu1KTUC1kcmaiAnI270")

The above is my console response error

I want to draw a poly line from my source to destination.

1 Answers1

0

I am using this way give it a try. May help you.

func drawPath(source: CLLocationCoordinate2D, destination: CLLocationCoordinate2D){

        let orgin = "\(source.latitude),\(source.longitude)"
        let destin = "\(destination.latitude),\(destination.longitude)"
        let url = "https://maps.googleapis.com/maps/api/directions/json?origin=\(orgin)&destination=\(destin)&mode=driving"

        Alamofire.request(url).responseJSON { response in

            switch response.result {
             case .success:
                let json = JSON(data: response.data!)
                let routes = json["routes"].arrayValue
                print(response)

             break
             case .failure(let error):
               print(error)
            }
        }
    }
Sreekuttan
  • 1,579
  • 13
  • 19