2012-01-25 38 views
4

我從這個方法如何獲取用戶在iphone SDK中的模擬器當前位置?

/*Region and Zoom*/ 
MKCoordinateRegion region; 
MKCoordinateSpan span; 
span.latitudeDelta=0.2; 
span.longitudeDelta=0.2; 

CLLocation *location1 = [locationManager location]; 

CLLocationCoordinate2D location = [location1 coordinate]; 

location.latitude = location.latitude; 
location.longitude = location.longitude; 
region.span=span; 
region.center = location; 

/*Geocoder Stuff*/ 

MKReverseGeocoder *geoCoder=[[MKReverseGeocoder alloc] initWithCoordinate:location]; 
geoCoder.delegate = self; 
[geoCoder start]; 
mapView.showsUserLocation = TRUE; 

[mapView setRegion:region animated:TRUE]; 
[mapView regionThatFits:region]; 

這工作完全,但獲取用戶的位置,當我嘗試運行模擬器,然後它就會在[mapView setRegion:region animated:TRUE];點這告訴它沒有得到緯度和經度墜毀這段代碼值。那麼我怎麼才能讓這段代碼在模擬器中完美運行。

我必須讓這段代碼在模擬器中運行,有可能嗎?

+0

模擬器不顯示當前位置 – Sarah

+1

是的我知道,但我必須這樣做,這樣纔有可能嗎? –

+0

http://stackoverflow.com/questions/6946966/iphone-simulator-4-3-with-xcode-4-is-not-showing-current-location – Sarah

回答

13

在iOS5模擬器默認情況下,它會在美國顯示一些位置。如果您想要更改該位置,請在iOS Simulator菜單中轉至調試 - >位置 - >自定義位置。 在那裏你可以設置緯度和經度,並相應地測試應用程序。這適用於mapkit,也適用於CLLocationManager。

10

試試這個路徑 -

轉到產品 - >編輯方案 - >選項 - >選擇允許位置模擬

它不會是你的確切位置!但至少你可以驗證你的代碼正在工作。

相關問題