我正在尝试使用MKMapView. 我遇到了一项任务,我已经在墙上撞了很长一段时间了——当注释彼此重叠时,将它们分组到一个集群中。我可以获得两个注释之间的距离(以米为单位),但是如何获得相对于缩放级别(latitudeDelta)的距离?理想情况下,我想知道两个注释何时相互重叠,例如考虑到它们的宽度和高度为 40x40。
我正在尝试向我的地图添加圆形叠加层。我跟着苹果文档走了这么远,但是当我运行应用程序时没有出现覆盖。这是我的代码...
@IBOutlet var map: MKMapView!
let location = CLLocationCoordinate2DMake(40.73085, -73.99750)
let regionRadius: CLLocationDistance = 5500
func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {
let diskRenderer: MKCircleRenderer = MKCircleRenderer.init()
diskRenderer.fillColor = UIColor.init(red: 0, green: 192, blue: 295, alpha: 1)
return diskRenderer
}
override func viewDidLoad() {
super.viewDidLoad()
let coordinateRegion = MKCoordinateRegionMakeWithDistance(location, regionRadius, regionRadius)
map.setRegion(coordinateRegion, animated: true)
let diskOverlay: MKCircle = MKCircle.init(centerCoordinate: location, radius: 5000)
map.addOverlay(diskOverlay)
// Do any additional setup after loading the view.
}
Run Code Online (Sandbox Code Playgroud)
我正在自学所有这些东西,所以如果我犯了一个明显的错误,请原谅我。
我有一个应用程序,应该在后台获取对象并使用它们的位置数据为它们生成地图快照。我自然尝试了 MKMapSnapshotter。
事实证明(在对黑色地图快照感到困惑数周之后)这个工具似乎只有在从主线程调用时才起作用,如下所示:
dispatch_async(dispatch_get_main_queue(), ^{
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithQueue:dispatch_get_main_queue() completionHandler:^(MKMapSnapshot * _Nullable snapshot, NSError * _Nullable error) {
//Use image here. Image would be completely black if not for the first line of code specifying main thread.
}];
});
Run Code Online (Sandbox Code Playgroud)
这是一个框架错误吗?
问题:这只在我的应用程序位于前台时运行。
我创建了一个地图,右上角有一个用户跟踪按钮。我想知道如何在加载时默认将状态设置为“followWithHeadlights”,以便它跟随用户当前位置,就像在 GPS 上一样?
负载时的当前行为: 按钮当前行为
加载时所需的行为: 按钮所需的行为
代码片段:
func setUserTrackingButton() {
// Mapkit tracking button
let trackingButton: MKUserTrackingBarButtonItem = MKUserTrackingBarButtonItem.init(mapView: mapView)
trackingButton.customView?.tintColor = UIColor(red:0.01, green:0.81, blue:0.37, alpha:1.0)
trackingButton.customView?.frame.size = CGSize(width: 50, height: 50)
let toolBarFrame = CGRect(origin: CGPoint(x: 0, y: 0) , size: CGSize(width: 50, height: 50))
let toolbar = UIToolbar.init(frame: toolBarFrame)
toolbar.barTintColor = UIColor.white
toolbar.isTranslucent = true
let flex: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil)
toolbar.items = [flex, trackingButton, flex]
let origin = CGPoint(x: self.view.frame.size.width - 85, …Run Code Online (Sandbox Code Playgroud) 嗨,我的项目中有一个 MapView,我需要从 MapView 中删除所有标签注释、地点。看起来像普通的地图视图
我尝试了以下代码,它工作正常,但我仍然得到一些建筑细节、街道名称和所有我想要的也被删除的只有用户位置可见
这是代码:
[mapView setShowsPointsOfInterest:NO];
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常并从 mapKit 中删除了默认位置图标,但没有删除所有图标和标签,如何从 MapKit 中删除所有默认图标和标签名称
这是我的问题:
当缩小并且属性showsUserLocation 设置为true 并且注释以用户位置为中心时,缩小时集群将消失。我不想要这个,它们应该总是可见的。displayPriority 的默认值设置为 required 所以我不知道如何解决这个问题。每个注释和集群都应该始终可见。当我将属性showsUserLocation 设置为false 或确保注释/集群不在当前位置附近时,它会起作用。
有两种方法可以重现我的问题:
代码
import UIKit
import MapKit
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
let mapView = MKMapView(frame: .zero)
private let locationManager = CLLocationManager()
override func viewDidLoad() {
view.addSubview(mapView)
mapView.translatesAutoresizingMaskIntoConstraints = false
mapView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
mapView.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true
mapView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
mapView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
mapView.delegate = self
mapView.showsUserLocation = true
}
override func viewDidAppear(_ animated: Bool) {
let authorizationStatus = CLLocationManager.authorizationStatus()
switch authorizationStatus { …Run Code Online (Sandbox Code Playgroud) 我对 Swift 和 SwiftUI 很陌生,我想在地图视图顶部添加一个用户跟踪按钮,这样用户的当前位置可以在点击时回到屏幕的中心。我已经有了地图视图和按钮,但未能使其工作。
这是 ContentView.swift 文件,我被困在了 **** 的地方:
import SwiftUI
import MapKit
struct ContentView: View {
var body: some View {
ZStack {
MapView(locationManager: $locationManager)
.edgesIgnoringSafeArea(.bottom)
HStack {
Spacer()
VStack {
Spacer()
Button(action: {
******
}) {
Image(systemName: "location")
.imageScale(.small)
.accessibility(label: Text("Locate Me"))
.padding()
}
.background(Color.white)
.cornerRadius(10)
.padding()
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是 MapView.swift:
import SwiftUI
import MapKit
import CoreLocation
import ECMapNavigationAble
struct MapView: UIViewRepresentable, ECMapNavigationAble{
var locationManager = CLLocationManager()
func makeUIView(context: UIViewRepresentableContext<MapView>) -> MKMapView {
MKMapView()
} …Run Code Online (Sandbox Code Playgroud) 如何将地图从iOS 13更改为暗模式?
我已从 UserInterfaceStyle 中选择退出,因此系统范围的颜色不适用于我,所以我将手动进行。
我在8:19看过苹果WWDC2019 - Session 236 的这段视频,但那是快照,我没看懂。
实际上我正在尝试类似的事情:
private var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
mapView.backgroundColor = .black
}
Run Code Online (Sandbox Code Playgroud)
但它不会将主题或外观或 traitCollection 更改为深色。
有什么建议吗?
我很困惑为我们公司创建一个 IndoorMap 以在 iPad 上显示它。关于Apple的新IndoorMaps-Program,我认为我找到了完美的解决方案。官方地图应用程序中的一些机场显示了很好的例子。但是我越深入这个话题,我的理解就越少。
在他们提到的有关 IMDF 文件的文档中,作为私人开发人员,
您需要自己创建 IMDF。好消息是有许多第三方平台和工具可以让创建和更新 IMDF 变得更容易。请参阅下面有关第三方平台的部分。
所以我研究了这些第三方平台并注意到,当我将它与他们提供的软件和地图 SDK 一起使用时,我只能创建 IMDF。所以我会让我依赖另一个平台和 SDK,这不符合我的兴趣。我没有发现任何关于一个平台/软件的东西可以简单地将一些平面图转换为 IMDF。诀窍在哪里?我想复杂吗?
IMDF 最令人困惑的部分是:IMDF 到底是什么?第三方平台使用室内地图的新文件对其进行宣传。另一方面,苹果提到
IMDF 是一种用于描述室内空间的数据模型。IMDF 输出为一组 GeoJSON 文件。
那么它是文件还是格式?获得一个工具来创建 GeoJSON 文件就足够了吗?
也许有人对这个主题有一点经验,可以为我的问题提供一些提示,或者甚至可以建议另一种更简单更好的解决方案来显示室内地图,例如仓库。
我MKMapView在 SwiftUI 中显示userTrackingMode设置为 时遇到了麻烦.follow。我正在展示一张地图:
struct ContentView: View {
var body: some View {
MapView()
}
}
Run Code Online (Sandbox Code Playgroud)
在这方面,MapView我 (a) 设置userTrackingMode和 (b) 确保我拥有使用中的权限。我一直在基于故事板的项目中使用这种模式。无论如何,MapView现在看起来像:
final class MapView: UIViewRepresentable {
private lazy var locationManager = CLLocationManager()
func makeUIView(context: Context) -> MKMapView {
if CLLocationManager.authorizationStatus() == .notDetermined {
locationManager.requestWhenInUseAuthorization()
}
let mapView = MKMapView()
mapView.showsUserLocation = true
mapView.userTrackingMode = .follow // no better is mapView.setUserTrackingMode(.follow, animated: true)
return mapView
}
func updateUIView(_ uiView: …Run Code Online (Sandbox Code Playgroud) mapkit ×10
ios ×6
swift ×6
objective-c ×3
swiftui ×2
cllocation ×1
cocoa-touch ×1
imdf ×1
ios-darkmode ×1
ios13 ×1
userlocation ×1
xcode ×1