2011-08-23 60 views
0

問它自我解釋的細節,但我仍然解釋了這個問題。爲什麼我無法在模擬器中獲取位置?

我是新來獲取當前應用程序的位置。我已經構建了一個應用程序,可以在文本視圖中爲我提供當前位置。

但是,當我運行該應用程序到xcode 4.0,我看不到任何位置要獲取。

正如我提到的很多例子,我是正確的編碼。但現在我想知道的是iPhone模擬器能夠獲取當前位置?

回答

1

在iPhone模擬器不給currentlocation.But它應該在Device.So嘗試它在設備上。

+0

確定。謝謝。我嘗試了很多,但沒有獲得經緯度。現在我開始知道iPhone模擬器不會爲它工作。謝謝。 –

-2

以下代碼將允許向您顯示用戶的當前位置;

[mapView setShowsUserLocation:YES]; 
1

如果您嘗試設備當前的經緯度將返回,但如果您嘗試在模擬器緯度= 0和經度= 0將返回。因爲用戶的經度和緯度是從iPhone中的設備返回的,但不在模擬器中。所以你最好在設備上試試它。

+0

是的,謝謝。我得到了Sollution爲什麼我沒有得到位置。謝謝。 –

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); 
} 

其工作設備我都沒

相關問題