简体   繁体   中英

ios location tracker problems(objective-c)

I am developing FitnessApp using objective-C. This app has a function to track location of walking user and draw path of user. I used CLocationManager and get user location in it's delegate. Here is my code.

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];
}

but result is very wrong, it is very shaking and ZIGZAG even I am running along street. Btw, I compared it with Google Map Navigation and it is correct, What I am wrong ? How should I do to develop GPS tracking module like Uber, Google map without shaking?

Plz help me.

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];
}

First ask the system if it provide location, then cal startupdatinglocation, and set it Stop to Know, Now everytime on location update , yougot your location ..

You have to develop with core motion. Generally above method has long delay and wrong location.

when you stay one position, then you will get several location exactly.

So that you have to use the core motion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM