我正在 MapKit/Swift 4 中开发地图,其中有很多注释。用户可以使用选择器视图选择他想要的注释(仅 1),并且该注释将被调用(就好像他已经按下了它一样)。如果方便的话,我们可以考虑改变这个注释点的颜色。关键是要在众多注释中突出显示这个特定的注释。
经过一番搜索,我发现了这个功能
func selectAnnotation(_ annotation: MKAnnotation, animated: Bool)
Run Code Online (Sandbox Code Playgroud)
我已经实现了以下功能:
func selectPoints() {
print("selectPoints called")
let annotation1 = MKPointAnnotation()
annotation1.coordinate = CLLocationCoordinate2D(latitude: 48.8596833, longitude: 2.3988939)
annotation1.title = "Temple"
annotation1.subtitle = "\(annotation1.coordinate.latitude), \(annotation1.coordinate.longitude)"
mapView.addAnnotation(annotation1)
mapView.selectAnnotation(annotation1, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
因此,如果我创建一个新注释,它就可以工作,但是我如何选择以前的注释点?但我没有任何继续前进的想法或暗示。
谢谢你的帮助。
编辑:输入注释的部分代码。
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let annotation = annotation as? Artwork {
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId)
if pinView == nil {
pinView = MKAnnotationView(annotation: annotation, reuseIdentifier: …Run Code Online (Sandbox Code Playgroud) 如何在最新版本的 Yandex Mapkit 上构建右键按钮?缩放和定位按钮。我只是创建地图类并感到困惑。文档非常少..
我想在城市或用户在地图上搜索的区域周围绘制边界。我正在使用 Google Place API 查找位置的纬度和经度。但我也想要城市或地区的边界。所以我可以在该区域周围绘制一个多边形来显示。
例如,如果用户搜索“美国纽约”,我想在地图上绘制仅覆盖纽约市的叠加层。
我可以在 ios 中使用任何 API 来查找地图上的整个区域吗?
我可以在 mapView 上绘制多边形,但是我需要找到多边形并手动缩放它。有没有办法自动执行此过程,例如调整中心多边形?我浏览过互联网并阅读了一些相关文章,其中大多数都是基于折线和点的。任何形式的帮助将不胜感激,因为我正在寻找解决方案一段时间。提前致谢。
使用以下方法在mapView上绘制多边形:-
func drawFence(coordinates: UnsafePointer<CLLocationCoordinate2D>, count: Int) {
let makePoly = MKPolygon(coordinates: coordinates, count: count)
mapview.addOverlay(makePoly)
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
guard let polyOverlay = overlay as? MKPolygon else { return MKOverlayRenderer() }
let polyRender = MKPolygonRenderer(polygon: polyOverlay)
polyRender.fillColor = #colorLiteral(red: 0.9764705882, green: 0.09803921569, blue: 0.2588235294, alpha: 0.6)
polyRender.strokeColor = #colorLiteral(red: 0.9764705882, green: 0.09803921569, blue: 0.2588235294, alpha: 1)
polyRender.lineWidth = 2
return polyRender
}
Run Code Online (Sandbox Code Playgroud) 是否有可能使用 Swift在 iOS 中显示特定国家/地区地图?
我已经搜索了很多,但大多数其他答案都建议仅使用缩放效果绑定地图。
但我认为这对我来说不是正确的解决方案。
我使用下面的代码来加载地图,但结果出来后,地图仍然以用户位置为中心而不是注释周围,因为我必须滚动到图钉才能看到。
Map(coordinateRegion: $region, showsUserLocation: true, annotationItems: searchResults) { dest in
MapAnnotation(coordinate: dest.coordinate, anchorPoint: CGPoint(x: 0.5, y: 0.5)) {
MapPin(coordinate)
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试让SwiftUI+ MapKit+LongPress手势正常工作。当我在 中添加地图时ContentView,效果很好。然后,我将.onLongPressGesture修改器添加到地图中,平移/缩放停止工作。长按虽然有效。
我正在处理的代码:
Map(coordinateRegion: $region, interactionModes: .all, showsUserLocation: true)
.onLongPressGesture {
// How do I get the location (Lat/Long) I am pressed on?
print("onLongPressGesture")
}
Run Code Online (Sandbox Code Playgroud)
另外,有没有办法从长按手势中获取纬度/经度?
希望使其SwiftUI仅使用即可工作,而不包含UIKit在UIViewRepresentable.
因此对于我们的地图,我们使用 MapKit。我们使用 MKPolygons 在地图上方叠加一个图层。此功能自 iOS15 起一直有效,但自 16.1 起,我们收到以下错误,并且应用程序冻结(不会崩溃)。
[VKDefault] Exceeded Metal Buffer threshold of 50000 with a count of 50892 resources, pruning resources now (Time since last prune:6.497636): Assertion with expression - false : Failed in file - /Library/Caches/com.apple.xbs/Sources/VectorKit/src/MDMapEngine.mm line - 1363
Metal API Validation Enabled [PipelineLibrary] Mapping the pipeline data cache failed, errno 22
另一个有趣的日志如下
[IconManager] No config pack found for key SPR London Landmarks知道如何手动清除金属缓存吗?
我一直在玩iPhone SDK,使用MapKit和Core Location.
你可以使用哪些技巧来更好地测试...同时仍然在模拟器上(很久以前我必须在我的iPhone上试用它).
有没有办法使用NSTimer并定期获取位置,航向,速度等"假装"值?
模拟器只提供1个位置......并且没有移动...真正限制了它的"测试"实用性.
如何添加"迷你地图" UITableViewController?
我想使用与地图应用程序相同的"设计/布局".请参阅:
