在我的应用程序中获取经度,纬度并计算速度。
首先获取用户当前位置的经度,纬度。使用此代码得到了它。
[[self mapView] setShowsUserLocation:YES];
locationManager = [[CLLocationManager alloc] init];
[ locationManager setDelegate:self];
// we have to setup the location manager with permission in later iOS versions
if ([ locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[ locationManager requestWhenInUseAuthorization];
}
[ locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *location = locations.lastObject;
[[self labelLatitude] setText:[NSString stringWithFormat:@"%.6f", location.coordinate.latitude]];
[[self labelLongitude] setText:[NSString stringWithFormat:@"%.6f", location.coordinate.longitude]];
[[self labelAltitude] setText:[NSString stringWithFormat:@"%.2f feet", location.altitude*METERS_FEET]];
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, 2*METERS_MILE, 2*METERS_MILE);
[[self mapView] setRegion:viewRegion animated:YES];
}
我的问题:如果用户移动新地点意味着经度,纬度会成功更改。如何保存用户当前位置并更新新位置。以及如何计算速度。帮助我,谢谢你。