1

I want to show path in google map. But i am unable to show my path. Please help me . This is my code. I am try lot of time in swift. Any help would be appreciated. Thanks in advance.

let camera = GMSCameraPosition.camera(withLatitude: 48.4843822562792, longitude: 35.0635632500052, zoom: 6)
               let mapView = GMSMapView.map(withFrame: .zero, camera: camera)
        self.view = mapView

        let manager = AFHTTPSessionManager()



        manager.requestSerializer = AFJSONRequestSerializer()

        manager.responseSerializer.acceptableContentTypes =  nil

        let urlString = "https://maps.googleapis.com/maps/api/directions/json?origin=48.4843822562792,35.0635632500052&destination=48.4893899423081,35.0640017911792&waypoints=48.4833428800255,35.0710221379995|48.4887622031403,35.0573639944196&key=AIzaSyDvS9TbaQ1WzP_3YX6TBrjoTNGhnFa0MBY"


        let urlwithPercentEscapes = urlString.addingPercentEncoding( withAllowedCharacters: .urlQueryAllowed)



        manager.get(urlwithPercentEscapes!, parameters: nil, success: { (operation, response) in

             let parsedData = JSON(response)


                        var path = GMSPath.init(fromEncodedPath: parsedData["routes"][0]["overview_polyline"]["points"].string!)
                        //GMSPath.fromEncodedPath(parsedData["routes"][0]["overview_polyline"]["points"].string!)

            print(path!)

                        var singleLine = GMSPolyline.init(path: path)
                        singleLine.strokeWidth = 7
                        singleLine.strokeColor = UIColor.green
                        singleLine.map = self.mapView


        }, failure: { (operation, error) in


        })
  • check this answer in objc https://stackoverflow.com/questions/22550849/drawing-route-between-two-places-on-gmsmapview-in-ios –  Oct 11 '17 at 07:54

0 Answers0