Question it self explain the detail, but still i have explained about the question.
I am new to fetch the location of the current Application. I have build one application that gives me the Current location in Text View.
But while i run that application in to xcode 4.0, I can't see any location to be fetch.
As i refer many example, i am right in coding. But now i want to know is IPhone Simulator able to fetch the current location ?
在iPhone模拟器中没有给出当前位置,但是应该可以在Device中工作,因此请在设备上尝试一下。
If you try it device current latitude and longitude will returns, but if you try it in simulator latitude=0 and longitude=0 will be return. Because user latitude and longitude is returns from GPS device which is in iPhone but not in simulator. So better you try it in device.
`in view did load
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);
}
ITS WORK IN DEVICE FINE WITH ME
以下代码将允许您显示用户的当前位置;
[mapView setShowsUserLocation:YES];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.