Closed ghost closed 6 years ago
Hello guys . I want to have a route on my google map app and I use this code -> ` //ROUTE
// Pass your source and destination coordinates in this method. func getPolylineRoute(from source: CLLocationCoordinate2D, to destination: CLLocationCoordinate2D){ let config = URLSessionConfiguration.default let session = URLSession(configuration: config) let url = URL(string: "http://maps.googleapis.com/maps/api/directions/json?origin=\(source.latitude),\(source.longitude)&destination=\(destination.latitude),\(destination.longitude)&sensor=false&mode=driving&key=**MY KEY**")! let task = session.dataTask(with: url, completionHandler: { (data, response, error) in if error != nil { print(error!.localizedDescription) }else{ do { if let json : [String:Any] = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any]{ let routes = json["routes"] as? [Any] let overViewPolyLine = routes?[0] as?[String:Any] let polyString = overViewPolyLine?["points"] as?String //Call this method to draw path on map self.showPath(polyStr: polyString!) } }catch{ print("error in JSONSerialization") } } }) task.resume() } func showPath(polyStr :String){ let path = GMSPath(fromEncodedPath: polyStr) let polyline = GMSPolyline(path: path) polyline.strokeWidth = 3.0 polyline.map = googleMapsView // Your map view }
.` I have a crush on this line of my codes , I don't know what should I do . Any answer would be appreciated ☺️
Hello guys . I want to have a route on my google map app and I use this code -> `
//ROUTE
.` I have a crush on this line of my codes , I don't know what should I do . Any answer would be appreciated ☺️