【发布时间】:2016-11-01 08:00:55
【问题描述】:
我正在尝试实时绘制折线,以向用户展示他们到目前为止所走的路线。我使用google map api,到目前为止,它可以毫无问题地显示用户的当前位置。但是折线不起作用(它根本不绘制折线)。在检查授权并在 didupdatelocations 内绘制折线后,我调用 startMonitoringSignificantLocationChanges。这是我的代码的相关部分:
extension MapViewController: CLLocationManagerDelegate {
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == .AuthorizedAlways {
locationManager.startUpdatingLocation()
mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true
locationManager.startMonitoringSignificantLocationChanges()
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = manager.location {
mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
path.addCoordinate(CLLocationCoordinate2D(latitude: location.coordinate.latitude,
longitude: location.coordinate.longitude))
let polyline = GMSPolyline(path: path)
polyline.strokeColor = UIColor.redColor()
polyline.strokeWidth = 3
polyline.map = mapView
locationManager.stopUpdatingLocation()
}
}
UPDATE-1
在注释掉 stopUpdatingLocation 线之后,它确实绘制了这条线。但是这条线是乱七八糟的。
UPDATE-2
我明白为什么这条线是一团糟而不是一条直线。这是因为 iphone 一直在更改当前位置(即使它是静止的),因此在一个小区域内绘制多条线。如何阻止 iphone 这样做?
UPDATE-3
我刚刚发现“Jumpy”当前位置不仅发生在我的应用程序中。它也发生在 GoogleMap 应用程序中。所以这可能是 Iphone/ios GPS 问题。
【问题讨论】:
-
你只需要从位置数据中去除噪音。基本上,如果新值只是它的差异只有 0.0001(类似),则忽略新的位置值
-
其实这个面积并没有那么小。它足够大,足以让用户转向不同的街道以将它们作为噪音过滤掉。我正在使用 iPhone 5 bty。
标签: ios google-maps swift2 xcode7