2016-06-29 2 views
0

나는 폴리 라인을 실시간으로 그려서 사용자에게 지금까지 찍은 경로를 보여주고 있습니다. Google지도 api를 사용하여 현재까지 문제없이 사용자의 현재 위치를 보여줍니다. 그러나 폴리 라인은 작동하지 않습니다 (폴리선을 전혀 그리지 않음). 나는 승인을 확인한 후 didupdatelocations 안의 폴리 라인을 그린 후 startMonitoringSignificantLocationChanges를 호출합니다.Google지도의 폴리 라인이 실시간으로 작동하지 않습니다.

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이 현재 위치를 일관되게 (고정되어 있더라도) 변경하기 때문에, 따라서 작은 영역에 여러 줄을 그립니다. 아이폰이 그렇게하지 못하게하려면 어떻게해야합니까?

UPDATE-3

난 그냥 "예민"현재 위치는 내 응용 프로그램에서 발생하지 않는 것을 발견. Google지도 앱에서도 발생합니다. 아마 Iphone/ios GPS 문제 일 겁니다.

+0

그냥 위치 데이터에서 노이즈를 제거해야합니다. 기본적으로 새 값이 단지 0.0001 (이와 비슷한 것)의 차이가있는 경우 새 위치 값을 무시하십시오. – Nishant

+0

실제로이 영역은 실제로 작지 않습니다. . 소음으로 필터링하기 위해 다른 거리로 돌고있는 사용자와 섞일만큼 커야합니다. 나는 IPhone 5 bty를 사용하고있다. – user30646

답변

1

정확하지 않은 위치 업데이트 또는 업데이트를 무시하면됩니다.

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
{ 
CLLocation *location = [locations lastObject]; 
    NSTimeInterval age = -[location.timestamp timeIntervalSinceNow]; 
    if (age > 120) return; // ignore old (cached) updates 
    if (location.horizontalAccuracy < 0) return; // ignore invalid updates 
    if (location.horizontalAccuracy <=10) //you can change 10 to 20 if you want more frequent updates 
    { 
    // this is a valid update 
    } 
} 

희망이 있습니다.

관련 문제