我正在iOS应用上工作,在地图上绘制折线以突出显示用户所采用的路线。我可以毫无问题地绘制多边形线。但是,这条线不是你在Googlemap上看到的简洁线条。正如你在图片中看到的那样,它有点像手绘一样诡异。为大图片道歉,因为我不知道如何在SO中调整它们的大小。
如何在图片中实现如下结果:
这是我负责绘制多边形线的代码:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = manager.location {
if (firstLoad) {
firstLoad = false
recentCoordinate = location.coordinate
mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: Constants.MapView.Zoom, bearing: 0, viewingAngle: Constants.MapView.ViewingAngle)
}
else {
mapView.animateToLocation(CLLocationCoordinate2D(latitude: location.coordinate.latitude,longitude: location.coordinate.longitude))
}
// this is suppose to filter out noise. I don't think it's working
let age = 0 - location.timestamp.timeIntervalSinceNow
if (age > 120) {
return; // ignore old (cached) updates
}
if (location.horizontalAccuracy < 0) {
return; // ignore invalid updates
}
if (location.horizontalAccuracy <= 10){
// this is a valid update
// Draw route as user moves along
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
// Save the coordinates to array
coordinateArray.append([location.coordinate.latitude, location.coordinate.longitude])
}
}
}