gpt4 book ai didi

ios - map 上特定位置的用户当前位置

转载 作者:行者123 更新时间:2023-11-29 00:34:07 24 4
gpt4 key购买 nike

  • MKMapView
  • 核心位置
  • Swift3.0

我有这样的需求:

创建一个应用程序,在其中我从 webservice 获取各个位置的Lat and Long 。使用 Custom AnnotationView 在 map 上绘制这些位置。除此之外,我还用自定义图像显示用户当前位置

这里一切正常正常

现在,当用户移动时,用户当前位置图钉会更改其位置,因此对此有一个重要的要求,我需要以使其粘在 map 底部的方式设置当前位置位置(只是距底部 100 像素)。

我做了一些 RND 并找到了一些有用的链接:

但这不再起作用了。请建议我如何在 iOS map 中设置用户当前位置图钉,使其始终位于 map 底部(距底部 100 像素以上)

所需的引脚位置: enter image description here

目前它显示在其他位置。

注意 - **不希望 Google map 提供此类功能

最佳答案

如果你一直在使用这样的mapView.setUserTrackingMode(.Follow,animated: true)那么用户位置将始终显示在 map 的中心,缩放/平移将自动调整每当用户位置更新时。

您需要禁用UserTrackingMode,然后使用func setVisibleMapRect(_ mapRect: MKMapRect, edgePadding insets: UIEdgeInsets,animated animate: Bool) 手动调整 map 缩放/平移 每当用户位置发生变化时。

我在类似情况下使用了以下代码

let annotationPoint = MKMapPointForCoordinate(mapView.userLocation.coordinate);
var zoomRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 1, 1);
annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
let pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 1, 1);
zoomRect = MKMapRectUnion(zoomRect, pointRect);
mapView.setVisibleMapRect(zoomRect, edgePadding: UIEdgeInsetsMake(40, 50, 160, 50), animated: true)

附注edgePadding 在这种情况下是你的 friend 。

关于ios - map 上特定位置的用户当前位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41057877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com