2012-01-25 37 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

试试这个路径 -

转到产品 - >编辑方案 - >选项 - >选择允许位置模拟

它不会是你的确切位置!但至少你可以验证你的代码正在工作。