这里怎么了?我正试图获得总行程,但当我开始开车回到点,我开始我的价值下降?需要修理的东西。谢谢。
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if (startLocation == nil)
self.startLocation = newLocation; //if this is the first update colocation called startlocation = new location
CLLocationDistance distanceBetween = [newLocation
distanceFromLocation:startLocation]; //here is my problem I think
NSString *tripString = [[NSString alloc] //convert to string
initWithFormat:@"%f",
distanceBetween];
distance.text = tripString; //update my distance label called distance
}发布于 2013-10-21 21:18:51
试试这种方法:
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if (startLocation == nil)
{
self.totalDistanceBetween = 0; // declare this variable
self.startLocation = newLocation;
}
CLLocationDistance distanceBetween = [newLocation distanceFromLocation:startLocation ];
startLocation = newLocation;
self.totalDistanceBetween += distanceBetween; // declare this variable
NSString *tripString = [[NSString alloc] //convert to string
initWithFormat:@"%f",
self.totalDistanceBetween];
distance.text = tripString; //update my distance label called distance
}https://stackoverflow.com/questions/19504796
复制相似问题