我正在使用CLLocationManger获取设备当前位置。一切都在模拟上很顺利。我检查了"允许位置模拟"并将澳大利亚悉尼定位为默认位置。我在模拟器上得到了很长的悉尼和很长的
我的问题是,当我尝试设备时,我仍然可以获得悉尼的位置,但我的设备当前位置是印度。
我的设备获取我在Xcode中设置的位置。
这是我的代码:
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = 1;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
#pragma mark delegate method which tell the current location
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
latitudeCurrentLocation = [NSString stringWithFormat:@"%f",newLocation.coordinate.latitude];
longitudeCurrentLocation= [NSString stringWithFormat:@"%f",newLocation.coordinate.longitude];
[locationManager stopUpdatingLocation];
locationManager=nil;
NSLog(@"OldLocation %f %f", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
}
请建议我该怎么做。
答案 0 :(得分:0)
在设备中运行此功能时,请选择“不要模拟位置”
答案 1 :(得分:0)
使用此委托方法并检查您的位置地址
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
以下是示例代码:
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:_locationManager.location
completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
NSLog(@"placemarks=%@",placemarks);
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"placemark.ISOcountryCode =%@",placemark.ISOcountryCode);
NSLog(@"placemark.country =%@",placemark.country);
NSLog(@"placemark.postalCode =%@",placemark.postalCode);
NSLog(@"placemark.administrativeArea =%@",placemark.administrativeArea);
NSLog(@"placemark.locality =%@",placemark.locality);
NSLog(@"placemark.subLocality =%@",placemark.subLocality);
NSLog(@"placemark.subThoroughfare =%@",placemark.subThoroughfare);
NSLog(@"stringlocation:%@",_cityString);
}];
_userLocation = [locations lastObject]; // This will give you co-ordinates
[_locationManager stopUpdatingLocation];
}