How to load google broken map display in tableview cell?

I use google direction api to get all route information. From the response, I pass the value "overview_polyline" to the GMSPath object. Unfortunately, this does not show a map. I applied the same logic on the previous screen and did a great job loading the polyline. Is my cell initialized before the map loads?

        let camera = GMSCameraPosition.camera(withLatitude: searchLocation.coordinate.latitude,
                                              longitude: searchLocation.coordinate.longitude, zoom: 8)
        let mapView = GMSMapView.map(withFrame: cell.viaMap.frame, camera: camera)

         let center = CLLocationCoordinate2D(latitude: MomentaryLatitude, longitude: MomentaryLongitude)

        mapView.isMyLocationEnabled = true

        cell.viaMap.addSubview(mapView)

        let marker = GMSMarker()

        marker.title = "Current Location"
        marker.snippet = "XXX"
        marker.map = cell.viaMap

        let path: GMSPath = GMSPath(fromEncodedPath: myPolyLine)!
        let routePolyline = GMSPolyline(path: path)
        routePolyline.map = cell.viaMap


        routePolyline.strokeWidth = 50
        routePolyline.strokeColor = UIColor.red
        routePolyline.map = cell.viaMap

        var bounds = GMSCoordinateBounds()

        let pathInt = Int((path.count()))

        for i in 0  ..< pathInt{
            bounds = bounds.includingCoordinate(path.coordinate(at: UInt(i)))
        }




        cell.viaMap.animate(with: GMSCameraUpdate.fit(bounds))
+4
source share

Source: https://habr.com/ru/post/1663950/


All Articles