如何从谷歌地图中删除此默认红色标记 iOS Swift

How do i remove this default red marker from google maps iOS Swift

提问人:Sankalp Kanungo 提问时间:12/3/2022 更新时间:12/3/2022 访问量:117

问:

我想删除这个红色别针。我正在将自定义引脚添加到源(黄色引脚)和目标(蓝色引脚),但我仍然不明白为什么这个红色引脚也显示? 这是代码:-

    func reDrawRoute(pickupCoordinate : CLLocationCoordinate2D, destinationCoordinate :CLLocationCoordinate2D, type: String) {
 //   func setMapMarkersRoute(vLoc: CLLocationCoordinate2D, toLoc: CLLocationCoordinate2D) {
        self.sourceMarker.map = nil
        self.destMarker.map = nil
        //add the markers for the 2 locations
        if type == "S2D" {
            self.sourceMarker = GMSMarker.init(position: pickupCoordinate)
            self.sourceMarker.icon = UIImage(named: "source")
            self.sourceMarker.map = gMapView
            
            self.destMarker = GMSMarker.init(position: destinationCoordinate)
            self.destMarker.icon = UIImage(named: "destination")
            self.destMarker.map = gMapView
        } else if type == "C2S" {
            self.carMarker.position = pickupCoordinate
            self.carMarker.icon = UIImage(named: "pin-car")
            self.carMarker.map = gMapView
            
            self.destMarker = GMSMarker.init(position: destinationCoordinate)
            self.destMarker.icon = UIImage(named: "source")
            self.destMarker.map = gMapView
        } else if type == "C2D" {
            self.carMarker.position = pickupCoordinate
            self.carMarker.icon = UIImage(named: "pin-car")
            self.carMarker.map = gMapView
            
            self.destMarker = GMSMarker.init(position: destinationCoordinate)
            self.destMarker.icon = UIImage(named: "destination")
            self.destMarker.map = gMapView
        }

        //zoom the map to show the desired area
        var bounds = GMSCoordinateBounds()
        bounds = bounds.includingCoordinate(pickupCoordinate)
        bounds = bounds.includingCoordinate(destinationCoordinate)
        self.gMapView.moveCamera(GMSCameraUpdate.fit(bounds))

        //finally get the route
        getRoute(from: pickupCoordinate, to: destinationCoordinate)

    }

这用于获取源和目标之间的路由坐标。

   func getRoute(from: CLLocationCoordinate2D, to: CLLocationCoordinate2D) {
        
        let source = MKMapItem(placemark: MKPlacemark(coordinate: from))
        let destination = MKMapItem(placemark: MKPlacemark(coordinate: to))

        let request = MKDirections.Request()
        request.source = source
        request.destination = destination
        request.requestsAlternateRoutes = false

        let directions = MKDirections(request: request)

        directions.calculate(completionHandler: { (response, error) in
            if let res = response {
                //the function to convert the result and show
                self.show(polyline: self.googlePolylines(from: res))
            }
        })
    }

此代码用于显示路线。

    private func googlePolylines(from response: MKDirections.Response) -> GMSPolyline {

        let route = response.routes[0]
        var coordinates = [CLLocationCoordinate2D](
            repeating: kCLLocationCoordinate2DInvalid,
            count: route.polyline.pointCount)

        route.polyline.getCoordinates(
            &coordinates,
            range: NSRange(location: 0, length: route.polyline.pointCount))

        let polyline = Polyline(coordinates: coordinates)
        let encodedPolyline: String = polyline.encodedPolyline
        let path = GMSPath(fromEncodedPath: encodedPolyline)
        return GMSPolyline(path: path)
        
    }

我正在使用这种方法来添加自定义标记。.

iOS 的 swift iphone xcode swift3

评论


答: 暂无答案