【问题标题】:Google map flickering on update current user location谷歌地图在更新当前用户位置时闪烁
【发布时间】:2018-06-26 07:10:31
【问题描述】:

我正在使用 Google 地图 在起点和终点之间绘制路径。 它完美地工作,当用户旅行时,使用这个委托函数更新当前位置和绘制路线。

public func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {

   drawPath() 

}

地图闪烁我正在使用此功能绘制路径

func drawPath()
{
   let urlString = "https://maps.googleapis.com/maps/api/directions/json?origin=\(origin)&destination=\(destination)&mode=driving"

    let url = URL(string: urlString)
    URLSession.shared.dataTask(with: url!, completionHandler: {
        (data, response, error) in

        if(error != nil){
            print("error")
        }else{
            DispatchQueue.main.async {
            do{
                let json = try JSONSerialization.jsonObject(with: data!, options:.allowFragments) as! [String : AnyObject]
                let routes = json["routes"] as! NSArray
                self.googleMapView?.clear()

                    for route in routes
                    {
                        let routeOverviewPolyline:NSDictionary = (route as! NSDictionary).value(forKey: "overview_polyline") as! NSDictionary
                        let points = routeOverviewPolyline.object(forKey: "points")
                        let path = GMSPath.init(fromEncodedPath: points! as! String)
                        let polyline = GMSPolyline.init(path: path)
                        polyline.strokeWidth = 8
                        polyline.strokeColor = #colorLiteral(red: 0.2420450151, green: 0.487836957, blue: 0.9020499587, alpha: 1)
                        let bounds = GMSCoordinateBounds(path: path!)
                        self.googleMapView!.animate(with: GMSCameraUpdate.fit(bounds, withPadding: 30.0))

                        polyline.map = self.googleMapView
                    }
            }catch let error as NSError{
                print("error:\(error)")
            }
                self.addMarker(loc: desti)

            }
        }
    }).resume()
}

在其他情况下,没有委托功能行进路线折线不清除,但当前位置更新。

谁能给个建议,谢谢。

【问题讨论】:

  • 尝试在真实设备上检查。
  • 是的,我正在检查真实设备并使用 gpx 文件进行测试。
  • @Leela 显示截图
  • 是的,我添加了截图

标签: ios swift google-maps


【解决方案1】:

我建议您在 viewdidload 中仅绘制一次路线,并在位置更改时更新标记位置。因此,这将消除路线图的闪烁,并在仓位变化时移动市场。

【讨论】:

  • 是的..我按照你的建议解决了这个问题..谢谢。
猜你喜欢
  • 1970-01-01
  • 2014-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-29
  • 2015-08-28
相关资源
最近更新 更多