质疑它自我解释细节,但我仍然解释了这个问题。
我是新手来获取当前应用程序的位置。我已经构建了一个应用程序,它在Text View中为我提供了当前位置。
但是当我将该应用程序运行到xcode 4.0时,我看不到任何要获取的位置。
正如我所说的那样,我正好在编码方面。但现在我想知道iPhone模拟器能够获取当前位置吗?
答案 0 :(得分:1)
在iPhone模拟器中没有给出currentlocation.But它应该在Device中工作。所以在设备上试试。
答案 1 :(得分:1)
如果您尝试设备当前纬度和经度将返回,但如果您在模拟器中尝试它,纬度= 0和经度= 0将返回。因为用户经度和经度是从iPhone中的GPS设备返回而不是在模拟器中。所以你最好在设备上试一试。
答案 2 :(得分:0)
`在视图中加载
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);
}
它在设备中的工作与我一起很好
答案 3 :(得分:-2)
以下代码将允许显示用户的当前位置;
[mapView setShowsUserLocation:YES];