- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 XCode 7.2 和 Swift 2.1 开发一个 iOS 应用程序,并且我已经在我的应用程序中成功地实现了 MapKit map 。 map 加载完美,并以用户当前位置为中心。
现在我想在用户将 map 中心移动到新位置时检索中心坐标。按下按钮(请参阅附加 gif 中的“设置网格引用”按钮)将“捕获”这个新位置的坐标,并显示在标签中。
Move from A to B and set new center coordinates
我最接近的答案是 here ,并且我已经实现了该代码,但我仍然无法弄清楚如何通过单击我创建的 IBOutlet 按钮使用坐标更新标签。
我在这里错过了什么?!
非常感谢任何帮助 - 提前致谢!
----------------后续问题----------------
既然我们已经解决了这个问题并且我们得到了用新的中心坐标填充的标签,我还有一个问题 - 很可能是菜鸟的疏忽,但我在这里的学习曲线很陡,所以请耐心等待我...
我们已经成功确定了中心坐标,现在它们在我们创建的函数中被设置为 mapLongitude 和 mapLatitude。
我有两个其他变量(newTargetLong 和 newTargetLat),它们构成将传递给下一个 View Controller 的值数组的一部分,我想:
let newTargetLong = mapLongitude
let newTargetLat = mapLatitude
以便可以使用 .append
指令将新的纬度和经度添加到数组中。
但出于某种原因,我无法从该函数中“取出”这两个值。我需要做什么才能做到这一点?
最佳答案
在类的顶部声明 var center = ""
以及其他声明。在下面的方法中,它应该自动改变center
的值:
func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
center = mapView.centerCoordinate
}
当您按下按钮时,将标签的值设置为中心的值。
self.yourLabelName.text = center
要显示为“纬度:...经度:...”,请执行以下操作:
func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
let mapLatitude = mapView.centerCoordinate.latitude
let mapLongitude = mapView.centerCoordinate.longitude
center = "Latitude: \(mapLatitude) Longitude: \(mapLongitude)"
print(center)
self.yourLabelName.text = center
}
如果想格式化坐标显示更友好一点:
center = "\(String(format: "%.5f", mapLatitude)), \(String(format: "%.5f", mapLongitude))"
根据您对小数位数的偏好调整 %.5f。
关于ios - 从 MapKit 中获取中心坐标并显示在 UILabel 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34378118/
我想在我的应用程序中显示 map 上两点之间的点对点路线。我正在使用 MKDirectionsRequest为此。我试图找到浦那到孟买之间的路线。我收到一个错误作为响应。 错误消息: Error Do
我想我可能在 iOS 6 的 mapkit API 中发现了一个错误,但由于我仍然认为自己是新手,我想我会在这里查看是否有人能指出我可能做错的事情。 我有一个应用程序已经工作了几个星期,其中有一个 m
这是我的第一个程序。而且,我正在实现 MapKit。以下是代码: import UIKit import MapKit class ViewController: UIViewController {
如何从 MapkitView 获取当前可见叠加层的列表(数组)? 背景 - 例如,我想在我的 mapkitview 上显示指向某些覆盖类型中心的方向箭头,但是如何获得可见的箭头?我看似乎没有办法做到这
我使用了 Apples WWDC 2017 的项目 tandm - 237“Mapkit 中的新功能”。 已经有一个带数组的data.plist命名的自行车和额外的词典有四个项目(键:值 - 对)。
我正在使用 iOS 11 集群,它工作得很好,基本上你只需要将标识符添加到 MKAnnotationView 的 clusteringIdentifier 属性。 一切正常,但我有一个问题,当用户从
我有一个MKMapView,在顶部有一个UISearchBar,我希望用户能够键入一个地址,并找到该地址并在其上放一个别针。我不知道如何将地址字符串转换为经度和纬度,因此我可以创建一个CLLocati
我想在 map 上画一条路线。 但不使用委托(delegate)的结构。 struct MapView : UIViewRepresentable { } func mapView(_ mapView
绘制的折线显示在建筑物下方。 如何使折线位于所有图层的顶部 请建议 将折线添加为 var coordinates = locationsArrToAdd.map({ (location: CLL
我有一个简单的 Mac 应用程序,不打算用于任何类型的分发;只是个人使用。该应用程序是 NSWindow其中包含一个 MKMapView .由于我没有 Mac 开发人员帐户,也不想要(请参阅“仅供个人
这是一个非常简单的问题。在 MapKit JS 中,如何将注释设置为选中的注释? 我已经在 map View 上有了注释并且可以访问我想要选择的注释。我觉得应该有一个类似于 MapKit 的方法(不是
我可以在我的应用程序中使用 Google map 街景吗? 最佳答案 不。 [填充字符以克服可疑的最小值] 关于xcode - MapKit 是否允许街景?,我们在Stack Overflow上找到一
我有一个功能,可以将注释放大到 map 上的一半,以及用户的位置,这样两者都可以在屏幕上看到。是否有显示其“内容”的注释方法,即模拟按下它?它在放大后立即弹出是理想的选择。 提前致谢。 最佳答案 您可
在我的应用程序中,我添加了很多引脚,并在 viewForAnnotaion 中,我在 MKPinAnnotaionView 上设置了 animatesDrop=TRUE。问题是,当有 200 多个引脚
我已经为此苦苦挣扎了几天,我什至重写了一半的代码来尝试另一种方式。 我从 csv 导入了注释,并用图 block 和副标题放置在 map 上,我徒劳地尝试添加一个标签来公开按钮,以便我可以看到点击了哪
我按照本教程制作了我的第一个应用程序: http://icodeblog.com/2009/12/21/introduction-to-mapkit-in-iphone-os-3-0/ 我真的很想知道
我是 iPhone 开发新手。我在 map 上添加了注释。我能够在 didSelectAnnotationView() 中捕获注释上的点击事件。但我想在用户点击注释时更改注释的图像。 最佳答案 设置图
所以我的 map 上散布了一堆注释...一切都很漂亮。现在我需要能够设置 map 的位置和缩放,以便它们完美契合。我怎样才能做到这一点? 最佳答案 来自苹果论坛... - (void)recenter
我是 iPhone 版 MapKit 的新手,尝试实现此功能,由于某种原因我看不到当前位置蓝点,其他人也有这个问题吗??? #import "DetailMapViewController.h" #i
我有一张显示多个注释的 map 。我想模仿“照片”内置应用程序(iOS 4)上“位置”选项卡的行为,其中当用户更改缩放级别时,注释会自动连接在一起或分开。 我该怎么做? 谢谢! 最佳答案 “照片”应用
我是一名优秀的程序员,十分优秀!