다음 단계를 사용하여 GPX 파일을 만듭니다.
프로젝트
- 이동 -> 아이폰 OS - -> 자원 및 GPX 지금 당신이로 GPX 파일에 작은 코드를 할 필요가
<!--
Provide one or more waypoints containing a latitude/longitude pair. If you provide one
waypoint, Xcode will simulate that specific location. If you provide multiple waypoints,
Xcode will simulate a route visitng each waypoint.
-->
<wpt lat="37.331705" lon="-122.030237"> // here change lat long to your lat long
<name>Cupertino</name> // here set name
<!--
Optionally provide a time element for each waypoint. Xcode will interpolate movement
at a rate of speed based on the time elapsed between each waypoint. If you do not provide
a time element, then Xcode will use a fixed rate of speed.
Waypoints must be sorted by time in ascending order.
-->
<time>2014-09-24T14:55:37Z</time>
</wpt>
을 : 14,
이제 GPX 파일에서 추가 한 위도의 위치를 길게 얻을 수 있습니다. 당신은 위치 서비스에 대한 NSLocationWhenInUseUsageDescription
및 NSLocationWhenInUseUsageDescription
을 설정할 필요가의 Info.plist에서
- : 다음는
UPDATE
위치를 가능하게하기위한 코드입니다.
이제 .H 클래스
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController<CLLocationManagerDelegate>
{
__weak IBOutlet UILabel *lblLat;
__weak IBOutlet UILabel *lblLong;
}
@property(strong,nonatomic) CLLocationManager *locationManager;
@end
하는 .m 클래스
- (void)viewDidLoad {
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
[self.locationManager requestWhenInUseAuthorization];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
lblLat.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
lblLong.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
}
}
근무 데모 코드 : https://github.com/nitingohel/UserCurrentLocation_Objc
위치 업데이트는 실제 기기에서 작동하도록되어 있습니다. 시뮬레이터에서 현재 위치를 가져올 수 없습니다. –
시뮬레이터를 사용하여 현재 위치를 가져올 수 없습니다. 장치를 사용하십시오. –
디버그> 위치> 사용자 정의 위치에서 위치를 설정 중이지만 아직 설정하고있는 위치가 표시되지 않습니다. – user6438311