根据用户位置将地图居中

发布于 2024-08-18 19:03:31 字数 784 浏览 2 评论 0原文

我想将地图(mapkit)以用户的位置为中心。我在模拟器中执行以下操作,但只得到一张没有内容的蓝色地图。我应该采取什么步骤?

MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;

CLLocationCoordinate2D location;
location.latitude = mapView.userLocation.location.coordinate.latitude;
location.longitude = mapView.userLocation.location.coordinate.longitude;

region.span=span;
region.center=location;
[self.mapView setRegion:region animated:TRUE];
[self.mapView regionThatFits:region];

上面的经度/纬度值为:

location.latitude = 1.0256307104653269e-305
位置.经度 = 1.2742349910917941e-313

--- 编辑 ---
我在这里找到了后续评论的答案:Mapkit UserLocation 发现事件。与下面的答案一起使用,即可提供解决方案。

I'd like to center a map (mapkit) against the user's location. I do the following in the simulator but only get a blue map with no content. What steps should I be taking?

MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;

CLLocationCoordinate2D location;
location.latitude = mapView.userLocation.location.coordinate.latitude;
location.longitude = mapView.userLocation.location.coordinate.longitude;

region.span=span;
region.center=location;
[self.mapView setRegion:region animated:TRUE];
[self.mapView regionThatFits:region];

The long/lat values from the above are:

location.latitude = 1.0256307104653269e-305
location.longitude = 1.2742349910917941e-313

--- EDIT ---
I found the answer to my follow up comment here: Mapkit UserLocation found event. Used with the answer below, that provides the solution.

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

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

发布评论

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

评论(1

暗地喜欢 2024-08-25 19:03:31

没有内容的蓝色地图通常意味着您位于海洋中的某个地方。缩小并检查您的坐标,您很可能位于非洲海岸的纬度 0.0 和经度 0.0 处。您是否检查过您的纬度和经度的值是什么?

您还可以尝试将 -setCenterCooperative:animated:userLocation 中心一起使用。

A blue map with no content usually means that you're somewhere in the ocean. Zoom out and check your coordinates, you're most likely off the coast of Africa at latitude 0.0 and longitude 0.0. Have you checked to see what values are in your latitude and longitude?

You could also try using -setCenterCoordinate: animated: with the userLocation center.

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