尝试使用 lat、lng 为 sqlite DB 绘制地图,但在地图绘制之前无法获取我的位置。哎呀!

发布于 2024-08-09 07:19:32 字数 1137 浏览 3 评论 0原文

我能做什么: 获取 100 个纬度和经度点的 sqlite DB,并将这些图钉放在地图上。看起来很棒!

我想做的是在绘制地图之前获取我的位置。但似乎:

  • (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

总是在 (void)viewDidLoad 运行后触发。无论我将其插入何处。

我需要做的是有一个启动屏幕,停在那里直到我找到一个位置,使用该纬度和经度来搜索我的 sqlite 数据库中距离我这么多英里的位置。

这是我的踪迹:

<块引用> <块引用>

输入-[RootViewController initWithTabBar]

输入-[RootViewController viewDidLoad]

输入 -[RootViewController locationManager:didUpdateToLocation:fromLocation:]

这就是我真正想要的:

<块引用> <块引用>

输入 -[RootViewController initWithTabBar]

输入 -[RootViewController locationManager:didUpdateToLocation:fromLocation:]

输入-[RootViewController viewDidLoad]

现在我在想(使用 tabbarcontroller),以某种方式我必须将其一直推回到我的应用程序委托?冻结整个应用程序直到我获得位置?这是我最新的想法。

感谢您提供任何提示、线索、片段......!!!我已经找了好几天了,一点运气都没有。

谢谢!!!!

What I can do:
Take a sqlite DB of 100 lat and lng points, and drop those pins on a map. Looks GREAT!

What I would like to do is get my location, BEFORE I draw my map. But it seems that:

  • (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

ALWAYS fires off AFTER (void)viewDidLoad runs. NO MATTER where I insert it.

What i need to do is have a splash screen, STOP there until I get a location, use that lat and lng to search my sqlite DB of locations within so many miles of me.

Here my trace:

Entering -[RootViewController initWithTabBar]

Entering -[RootViewController viewDidLoad]

Entering -[RootViewController locationManager:didUpdateToLocation:fromLocation:]

And here's what I really want:

Entering -[RootViewController initWithTabBar]

Entering -[RootViewController locationManager:didUpdateToLocation:fromLocation:]

Entering -[RootViewController viewDidLoad]

Now I'm thinking (working with a tabbarcontroller), do somehow I have to push this all the way back to my app delegate? Freeze the entire app until I get a location? That's my latest thoughts.

thanks for any tips, leads, snippets ... !!! I've been looking for days, no luck at all.

thanks!!!!

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

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

发布评论

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

评论(1

瑕疵 2024-08-16 07:19:32

您绝对不想“冻结”应用程序,并且您肯定希望在应用程序委托的 applicationDidFinishLaunching: 方法中做尽可能少的工作。我可能建议:

  • 有两个视图:一个是带有地图的“真实”视图,(大概)由某个视图控制器控制。另一个只是一个简单的“等待”视图,其中包含给用户的消息和 UIActivityIndi​​catorView 或类似的东西。
  • 当您的应用程序启动时,在应用程序的窗口中加载并显示等待视图,然后启动位置管理器以查找用户的当前位置。
  • 当您获得足够的位置信息时,加载真实视图,将其添加到窗口中,然后删除等待视图。 (也许有一个漂亮的交叉淡入淡出动画或其他东西。)

您还可以添加两个视图,然后在正确的时间翻转它们的隐藏属性。但重点是为用户提供一些可看的东西,同时不试图对抗 Core Location 固有的异步特性。

You definitely don't want to "freeze" the app, and you definitely want to do as little work in your app delegate's applicationDidFinishLaunching: method as possible. What I might recommend:

  • Have two views: one is the "real" view with the map, (presumably) controlled by some view controller. The other is just a simple "waiting" view with a message to the user and a UIActivityIndicatorView, or something like that.
  • When your app launches, load and display the waiting view in your app's window, and kick off the location manager to find the user's current location.
  • When you've got enough location information, load the real view, add it to the window, and remove the waiting view. (Maybe with a nice cross-fade animation or something.)

You could also add both views, and just flip their hidden properties at the right time. But the point is to give the user something to look at, while not trying to fight the inherently asynchronous nature of Core Location.

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