2017-03-02 116 views
0

我正在使用objective-C開發FitnessApp。 這個應用程序有一個功能,跟蹤步行用戶的位置和繪製用戶的路徑。 我使用CLocationManager並獲取用戶在其代理中的位置。 這是我的代碼。ios位置跟蹤器問題(objective-c)

myLocation.desiredAccuracy = kCLLocationAccuracyBest ; 
myLocation.distanceFilter = 12 ; 
myLocation.activityType = CLActivityTypeAutomotiveNavigation; 
myLocation.delegate = self; 
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
{ 
CLLocation *newLocation = locations.lastObject; 
GMSMarker *marker = [[GMSMarker alloc] init]; 
marker.position = newLocation.coordinate; 
marker.map = mapView; 
GMSCameraPosition *camera = [GMSCameraPosition cameraWithTarget:newLocation.coordinate zoom:ZOOM]; 
[mapView animateToCameraPosition:camera]; 
} 

但結果是非常錯誤的,它是非常動搖和ZIGZAG甚至我沿着街道跑。順便說一句,我將它與谷歌地圖導航進行了比較,這是正確的, 我錯了什麼?我應該如何開發像Uber這樣的GPS追蹤模塊,Google地圖不會晃動?

Plz幫助我。

回答

0
self.locationManager = [[CLLocationManager alloc] init]; 
self.locationManager.delegate = self; 
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) 
{ 
    [self.locationManager requestWhenInUseAuthorization]; 

    [self.locationManager startUpdatingLocation]; 
    self.locationManager.pausesLocationUpdatesAutomatically = NO; 

    [self updateMapWithCoordinates:self.userLocationcoordinates]; 
} 

首先要求系統,如果它提供的位置,然後CAL startupdatinglocation,並將其設置停止知道, 現在每次上位置更新,yougot您的位置..

+0

[self updateMapWithCoordinates:self.userLocationcoordinates]; 我是一個本地方法來更新地圖位置,並調用代理上的同一個 –

+0

謝謝。穆罕默德。但我編寫了這個代碼來獲得授權。但結果是錯誤的,路徑是ZIGZAG不是直線。如果你有完整的源代碼片段來跟蹤位置和繪製路徑,那麼讓我知道它。我會感激。謝謝 – onefire

0

你有核心運動發展。以上方法一般都有很長的延遲和錯誤的位置。

當你保持一個位置,那麼你會準確地得到幾個位置。

這樣你就必須使用核心運動。