如何在iphonesdk的模拟器中获取用户的当前位置



我从这个方法获取用户位置

/*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];的点上崩溃,这告诉它没有得到纬度和经度值。那么,我如何才能让这段代码在模拟器中完美运行呢。

我必须让这个代码在模拟器中运行,这可能吗?

默认情况下,在iOS5模拟器上,它将显示美国的某个位置。如果您想更改该位置,请在iOS模拟器菜单中,转到调试->位置->自定义位置。在那里,你可以设置纬度和经度,并相应地测试应用程序。这适用于mapkit和CLLocationManager。

尝试此路径-

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

这不会是你的确切位置!但至少您可以验证您的代码是否正常工作。

最新更新