2016-06-29 9 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が(固定されていても)現在の位置を一貫して変更しているためです。したがって、小さな領域に複数の線を描画します。どのように私はそれをやってからiPhoneを停止するのですか?

UPDATE-3

私はちょうど「とびとび」現在の場所は私のアプリでは起こらないことが分かりました。 GoogleMapアプリでも発生します。これはおそらく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 
    } 
} 

希望すると便利です。

関連する問題