【发布时间】:2011-08-23 10:16:00
【问题描述】:
问题它自己解释细节,但我仍然解释了这个问题。
我是获取当前应用程序位置的新手。我已经构建了一个应用程序,它为我提供了文本视图中的当前位置。
但是当我在 xcode 4.0 中运行该应用程序时,我看不到任何要获取的位置。
正如我提到的许多示例,我在编码方面是正确的。但现在我想知道 iPhone Simulator 是否能够获取当前位置?
【问题讨论】:
问题它自己解释细节,但我仍然解释了这个问题。
我是获取当前应用程序位置的新手。我已经构建了一个应用程序,它为我提供了文本视图中的当前位置。
但是当我在 xcode 4.0 中运行该应用程序时,我看不到任何要获取的位置。
正如我提到的许多示例,我在编码方面是正确的。但现在我想知道 iPhone Simulator 是否能够获取当前位置?
【问题讨论】:
在 iPhone 模拟器中没有给出当前位置。但它应该在设备中工作。所以在设备上尝试一下。
【讨论】:
如果您尝试它,设备当前的纬度和经度将返回,但如果您在模拟器中尝试,则返回纬度=0 和经度=0。因为用户的纬度和经度是从 iPhone 中的 GPS 设备返回的,而不是模拟器中的。所以最好在设备中尝试一下。
【讨论】:
`在视图中确实加载了
locationManager=[[CLLocationManager alloc] init];
locationManager.delegate=self;
appDelegate.IsFromRefreshPosition=YES;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
if ([CLLocationManager locationServicesEnabled])
{
[locationManager startUpdatingLocation];
}
geocoarder returns the plackmark of current location
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
currentLocation = newLocation;
[currentLocation retain];
[locationManager stopUpdatingLocation];
NSLog(@"%f %f",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);
geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:currentLocation.coordinate];
[geocoder setDelegate:self];
[geocoder start];
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"locationManager:%@ didFailWithError:%@", manager, error);
}
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder1 didFindPlacemark:(MKPlacemark *)placemark
{
NSLog(@"The geocoder has returned: %@",[placemark addressDictionary]);
NSLog(@"CountryName :",[[placemark addressDictionary] objectForKey:@"Country"]);
NSLog(@"cityName :",[[placemark addressDictionary] objectForKey:@"City"]);
NSLog(@"After SubLocality %@",Addressstr);
}
}
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder1 didFailWithError:(NSError *)error
{
NSLog(@"reverseGeocoder:%@ didFailWithError:%@", geocoder, error);
}
它在我的设备中工作得很好
【讨论】:
以下代码将允许向您显示用户的当前位置;
[mapView setShowsUserLocation:YES];
【讨论】: