私は現在位置を取得するには、次のコードを使用しています、私はcorelocationフレームワークにObjective Cの中で、緯度と経度で現在位置を取得する方法を
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
NSLog(@" Current Latitude : %@",lat);
//latLabel.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
NSLog(@" Current Longitude : %@",longt);
//longLabel.text = longt;
}
を追加している。しかし、私はつまり、デフォルト値を取得していますLatitude:42°17'36.8898 "、経度:-71°27'43.1003" 現在のLatitude:N 12°56 '11.5624 "と経度:E 77°32' 41.0834"です。正確な緯度と経度を取得する方法。 ここで私は間違いをしているか、他の方法や関数、フレームワークを追加する必要があります。
ありがとうございました。
実際のデバイスまたはシミュレータでテストしましたか? –
端末で位置情報サービスを有効にしましたか? –
@XSlash私はシミュレータでテストしました。 – shasha