iPhone LocationManager - 在应用程序启动时获取坐标

发布于 2024-11-10 15:23:41 字数 397 浏览 6 评论 0原文

我通过 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 获取位置。当你移动时它应该可以工作(不能在模拟器中真正测试它,至少我不知道如何),但是当我第一次加载应用程序时,地图视图专注于整个世界,而不仅仅是我的位置。我可以调用该方法来更改第一次查看时的位置吗? 这是我当前的代码(如果有帮助的话): http://pastebin.com/9Sb2xVmE http://pastebin.com/rh9WB2ca

I'm getting the location through - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation. It should work when you move (can't really test it in simulator, at least I don't know how) but when I first load the app, the mapview is focused on the whole world, not just my location. Can I anyhow call the method to change the location on first view?
Here is my current code if it helps:
http://pastebin.com/9Sb2xVmE
http://pastebin.com/rh9WB2ca

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

落在眉间の轻吻 2024-11-17 15:23:41

如果您使用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];)
  • 中提到的代码地点经理的代表?

我建议您访问此页面:获取位置使用 Objective-C 的 iOS 设备,并逐步按照教程进行操作。那应该可以帮助你。

另外,这是 Mapkit 文档

祝您的项目好运:]

If your using mapkit:

Have you tried

setRegion:(MKCoordinateRegion)region animated:(BOOL)animated

Example:

CLLocationCoordinate2D coord = {latitude: 61.2180556, longitude: -149.9002778};
MKCoordinateSpan span = {latitudeDelta: 0.2, longitudeDelta: 0.2};
MKCoordinateRegion region = {coord, span};

[mapView setRegion:region];

this should zoom the mapview to your desired size, while maintaining focus on the center.

If your using CoreLocation:

Heres a checklist of what might have gone wrong:

  • Did you remember to import
  • Do you have a location manager (locationManager = [[CLLocationManager alloc] init];)
  • Is the code mentioned within the delegate of the location manager ?

I advise you to go to this page : Getting location of a iOS device with objective-C and follow the tutorial bit by bit. That should help you out.

Also, heres the mapkit docs

Best of luck with your project :]

甜柠檬 2024-11-17 15:23:41

我们无法通过在模拟器中运行来获取当前位置。如果您在设备中运行该应用程序,它将显示正确的位置。在模拟器中,它将显示默认位置为 califorina(苹果头四分之一)。

we cant able to get the current location by running it in simulator. if you run the application in device it will show the correct location. In simulator it will show the default loaction as califorina(apple head quaters).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文