- (voID)locationManager:(CLLocationManager *)manager dIDUpdatetoLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ if(!newLocation) return; if ((oldLocation.coordinate.latitude != newLocation.coordinate.latitude) && (oldLocation.coordinate.longitude != newLocation.coordinate.longitude)) { CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:oldLocation.coordinate.latitude longitude:oldLocation.coordinate.longitude]; CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.latitude]; CLLocationdistance distance = ([loc2 distanceFromLocation:loc1]) * 0.000621371192; //distance = distance; NSLog(@"Total distance %f in miles",distance); }}
由于某种原因,它打印出类似5678.32英里的东西.这个位置非常固定,根本不动.
解决方法CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.(!!!!!)latitude longitude:newLocation.coordinate.(!!!!!)latitude];总结
以上是内存溢出为你收集整理的使用CLLocation计算距离iOS MapKit全部内容,希望文章能够帮你解决使用CLLocation计算距离iOS MapKit所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)