지도 응용 프로그램이 있습니다. 현재 위치에서 특정 위치로 이동할 때 나는에 의해 커버되는 거리를 계산하고 싶습니다. 사람의 현재 속도, 사람의 평균 속도. 아무도이 문제를 해결하는 데 도움이 나를.이 문제를 해결하기 위해 어떤 sloution을 제공하십시오. 감사합니다현재 위치에서 특정 위치로 이동하는 평균 속도를 계산하는 방법
7
A
답변
6
당신의 수용률을 향상시킵니다. 다음 방법을 사용하여 거리를 킬로미터 또는 킬로미터 단위로 표시하십시오. 당신은 당신의 헤더 파일에 timer를 선언해야합니다.
//SpeedViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MobileCoreServices/UTCoreTypes.h>
@interface SpeedViewController : UIViewController <CLLocationManagerDelegate,UINavigationControllerDelegate>
{
CLLocationManager *locManager;
CLLocationSpeed speed;
NSTimer *timer;
CLLocationSpeed currentSpeed;
float fltDistanceTravelled;
}
@property (nonatomic,retain) NSTimer *timer;
-(float)getDistanceInKm:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;
-(float)getDistanceInMiles:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;
@end
//SpeedViewController.h
#import "SpeedViewController.h"
#define kRequiredAccuracy 500.0 //meters
#define kMaxAge 10.0 //seconds
#define M_PI 3.14159265358979323846264338327950288 /* pi */
@implementation SpeedViewController
@synthesize timer;
- (void)startReadingLocation {
[locManager startUpdatingLocation];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
CLLocationManager *locationManager=[[CLLocationManager alloc] init];
locationManager.delegate=self;
locationManager.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
[locationManager startUpdatingLocation];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"new->%d old->%d",(newLocation==NULL),(oldLocation==NULL));
if(newLocation && oldLocation)
{
fltDistanceTravelled +=[self getDistanceInKm:newLocation fromLocation:oldLocation];
}
}
//this is a wrapper method to fit the required selector signature
- (void)timeIntervalEnded:(NSTimer*)timer {
fltDistanceTravelled=0;
[self startReadingLocation];
}
-(float)getDistanceInKm:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
float lat1,lon1,lat2,lon2;
lat1 = newLocation.coordinate.latitude * M_PI/180;
lon1 = newLocation.coordinate.longitude * M_PI/180;
lat2 = oldLocation.coordinate.latitude * M_PI/180;
lon2 = oldLocation.coordinate.longitude * M_PI/180;
float R = 6371; // km
float dLat = lat2-lat1;
float dLon = lon2-lon1;
float a = sin(dLat/2) * sin(dLat/2) + cos(lat1) * cos(lat2) * sin(dLon/2) * sin(dLon/2);
float c = 2 * atan2(sqrt(a), sqrt(1-a));
float d = R * c;
NSLog(@"Kms-->%f",d);
return d;
}
-(float)getDistanceInMiles:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
float lat1,lon1,lat2,lon2;
lat1 = newLocation.coordinate.latitude * M_PI/180;
lon1 = newLocation.coordinate.longitude * M_PI/180;
lat2 = oldLocation.coordinate.latitude * M_PI/180;
lon2 = oldLocation.coordinate.longitude * M_PI/180;
float R = 3963; // km
float dLat = lat2-lat1;
float dLon = lon2-lon1;
float a = sin(dLat/2) * sin(dLat/2) + cos(lat1) * cos(lat2) * sin(dLon/2) * sin(dLon/2);
float c = 2 * atan2(sqrt(a), sqrt(1-a));
float d = R * c;
NSLog(@"Miles-->%f",d);
return d;
}
@end
추가 질문이있는 경우 의견을 남기십시오. 나는이 장치를 테스트하지 않았지만 논리적으로 작동해야합니다.
는 도움이되기를 바랍니다.
2
관련 문제
- 1. 현재 위치에서 대상으로 이동하는 jQuery 스크롤
- 2. 코어 위치로 속도를 계산하는 방법은 무엇입니까?
- 3. UITextView의 특정 위치에서 NSString의 NSRange를 계산하는 방법
- 4. 그래픽 모드에서 위치로 이동하는 방법
- 5. 안드로이드의 현재 속도를 계산하는 좋은 방법은 무엇입니까?
- 6. 웹 브라우저 구성 요소에서 위치로 이동하는 방법?
- 7. FileReader의 readLine()을 이전 위치로 이동하는 방법
- 8. 평균 데이터 흐름 속도를 계산 하시겠습니까?
- 9. 특정 위치에서 비디오를 재생하는 방법?
- 10. 아이폰을 사용하여 우리 차의 속도를 계산하는 방법
- 11. jQuery를 사용하여 div를 페이지의 특정 위치로 이동하는 방법은 무엇입니까?
- 12. 현재 위치로 MKMapView로드하기
- 13. 특정 크기의 하위 섹션을 파이썬으로 평균 계산하는 방법은 무엇입니까?
- 14. 한 위치에서 다른 위치로 파일 복사
- 15. scrollView의 특정 섹션으로 이동하는 방법
- 16. numpy : 특정 지역에서 평균 계산
- 17. 특정 위치로 향하는 화살표 표시
- 18. MapView의 줌 버튼을 다른 위치로 이동하는 방법은 무엇입니까?
- 19. UITableView 특정 위치로 스크롤
- 20. 그리드 위치에서 행/열을 계산하는 방법은 무엇입니까?
- 21. WPF ScrollViewer의 내용을 특정 위치로 스크롤하는 방법
- 22. ViewFlipper를 사용하여 특정 뷰로 이동하는 방법?
- 23. 현재 스크롤 값을 설정하는 방법
- 24. 특정 위치에서 요소 제거
- 25. 특정 위치에서 CATransition 시작
- 26. 특정 위치에서 문자열에 값을 삽입하는 방법 C#
- 27. div 스크롤바를 특정 위치로 설정하십시오.
- 28. 현재 URL로 이전 방문 페이지로 이동하는 방법
- 29. 플레이어가 특정 경로를 이동하는 것을 거부하는 방법?
- 30. 현재 위치에서 Plist 파일까지의 거리
startUpdatingLocation 메서드를 알고 있습니다 .is startReadingLocation 및 startUpdatingLocation same – Rani
개발자 설명서에서 startReadingLocation 메서드를 검색했지만 stopupdatinglocation 및 startupdatinglocation 만 포함되어 있습니다. readinglocation 메소드는 표준 메소드 또는 사용자 정의 – Rani
@ 라니 사과드립니다. 코드에 해당 메소드를 넣는 것을 잊어 버렸습니다. 코드를 업데이트했습니다. –