Google地图上的路线图在自定义图钉上显示阴影

时间:2019-12-03 04:30:28

标签: ios google-maps swift5

我已经在GoogleMap的两个位置之间实施了路线绘制。我为源和目标位置设置了自定义Pin。

不过,我尚未为该自定义图钉实现任何阴影。尽管如此,它仍然在引脚上显示阴影。我不想显示阴影。请帮忙!

当前正在显示,

enter image description here

应该是这样

enter image description here

这是代码

import GoogleMaps

override func viewDidAppear(_ animated: Bool) {
        loadMapView()
}

func loadMapView() {
        let camera = GMSCameraPosition.camera(withLatitude: -33.9320447, longitude: 151.1597271, zoom: 12)
        mapView = GMSMapView.map(withFrame: self.viewMap.bounds, camera: camera)
        viewMap.addSubview(mapView!)
        getRouteSteps(from: CLLocationCoordinate2D(latitude: -33.9320447, longitude: 151.1597271), to: CLLocationCoordinate2D(latitude: -33.8641859, longitude: 151.2165708), mapView: mapView, sourceTitle: "Opera House", sourceSnippet: "Sydney", destinationTitle: "Royal Botanic Gardens", destinationSnippet: "Sydney")
    }

//MARK:- Google Map Functions
func getRouteSteps(from source: CLLocationCoordinate2D, to destination: CLLocationCoordinate2D, mapView:GMSMapView?, sourceTitle : String, sourceSnippet : String, destinationTitle : String, destinationSnippet : String) {

    let session = URLSession.shared

    let url = URL(string: "https://maps.googleapis.com/maps/api/directions/json?origin=\(source.latitude),\(source.longitude)&destination=\(destination.latitude),\(destination.longitude)&sensor=false&mode=driving&key=\(googleMapAPIKey)")!

    let task = session.dataTask(with: url, completionHandler: {
        (data, response, error) in

        guard error == nil else {
            print(error!.localizedDescription)
            return
        }

        guard let jsonResult = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any] else {
            print("error in JSONSerialization")
            return
        }

        guard let routes = jsonResult["routes"] as? [Any] else {
            return
        }

        guard let route = routes[0] as? [String: Any] else {
            return
        }

        guard let legs = route["legs"] as? [Any] else {
            return
        }

        guard let leg = legs[0] as? [String: Any] else {
            return
        }

        guard let steps = leg["steps"] as? [Any] else {
            return
        }
          for item in steps {
            guard let step = item as? [String: Any] else {
                return
            }

            guard let polyline = step["polyline"] as? [String: Any] else {
                return
            }

            guard let polyLineString = polyline["points"] as? String else {
                return
            }

            //Call this method to draw path on map
            DispatchQueue.main.async {
                drawPath(from: polyLineString, mapView: mapView, source: source, destination: destination, sourceTitle: sourceTitle, sourceSnippet: sourceSnippet, destinationTitle: destinationTitle, destinationSnippet: destinationSnippet)
            }
        }
    })
    task.resume()
}

func drawPath(from polyStr: String, mapView:GMSMapView?, source: CLLocationCoordinate2D, destination: CLLocationCoordinate2D, sourceTitle : String, sourceSnippet : String, destinationTitle : String, destinationSnippet : String){
    let path = GMSPath(fromEncodedPath: polyStr)
    let polyline = GMSPolyline(path: path)
    polyline.strokeWidth = 3.0
    polyline.strokeColor = .black
    polyline.map = mapView // Google MapView

    // Creates a markers
    let marker = GMSMarker()
    marker.position = source
    marker.icon = UIImage(named: AppImages.Pin_red)
    marker.title = sourceTitle
    marker.snippet = sourceSnippet
    marker.map = mapView

    let marker1 = GMSMarker()
    marker1.position = destination
    marker1.icon = UIImage(named: AppImages.Map_pin_orange)
    marker1.title = destinationTitle
    marker1.snippet = destinationSnippet
    marker1.map = mapView
}

在这里,我将附加为标记图标设置的图像

enter image description here

0 个答案:

没有答案