我正在通过- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
. 它应该在你移动时工作(不能在模拟器中真正测试它,至少我不知道如何)但是当我第一次加载应用程序时,地图视图专注于整个世界,而不仅仅是我的位置。我可以无论如何调用该方法来更改第一个视图的位置吗?如果有帮助,这是我当前的代码:http:
//pastebin.com/9Sb2xVmE
http://pastebin.com/rh9WB2ca
问问题
550 次
2 回答
2
如果您使用 mapkit:
你有没有尝试过
setRegion:(MKCoordinateRegion)region animated:(BOOL)animated
例子:
CLLocationCoordinate2D coord = {latitude: 61.2180556, longitude: -149.9002778};
MKCoordinateSpan span = {latitudeDelta: 0.2, longitudeDelta: 0.2};
MKCoordinateRegion region = {coord, span};
[mapView setRegion:region];
这应该将地图视图缩放到您想要的大小,同时保持对中心的关注。
如果您使用 CoreLocation:
以下是可能出错的清单:
- 你记得导入吗
- 你有位置管理器吗(locationManager = [[CLLocationManager alloc] init];)
- 位置经理的代表中是否提到了代码?
我建议您访问此页面:Getting location of a iOS device with objective-C并逐步按照教程进行操作。那应该可以帮助你。
此外,这是 mapkit 文档
祝你的项目好运:]
于 2011-06-01T17:21:20.700 回答
0
我们无法通过在模拟器中运行它来获取当前位置。如果您在设备中运行应用程序,它将显示正确的位置。在模拟器中,它会将默认位置显示为 califorina(apple head quaters)。
于 2011-06-01T17:20:08.920 回答