首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >确定准确行程

确定准确行程
EN

Stack Overflow用户
提问于 2013-10-21 21:09:59
回答 1查看 122关注 0票数 0

这里怎么了?我正试图获得总行程,但当我开始开车回到点,我开始我的价值下降?需要修理的东西。谢谢。

代码语言:javascript
复制
    -(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


}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-21 21:18:51

试试这种方法:

代码语言:javascript
复制
-(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
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19504796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档