Swift 3 - 在地图上显示坐标

标准

我需要帮助。我试图在地图上显示我的坐标。我正在使用 MVC 模型构建我的项目。但是我确实收到一个错误,说我不能使用 CLLocationDegrees,我必须改用 CLLocationcoordinates2D。在下面查看我的代码。

编辑:更新了我的代码,现在它可以工作了!感谢您的回答!

这是我保存信息的地方(如果你能这么说?)

import Foundation
import MapKit

struct User {
let name: String
let position: CLLocationCoordinate2D

}

这是我的模型:

import LBTAComponents
import CoreLocation

class HomeDataSource: Datasource {

let users: [User] = {
    let position = CLLocationCoordinate2D(latitude: 37.33233141, longitude: -122.0312186)

    let sebbeUser = User(name: "Sebbe", position: position)



    return [sebbeUser]

}()



override func cellClasses() -> [DatasourceCell.Type] {
    return [UserCell.self]
}

override func item(_ indexPath: IndexPath) -> Any? {
    return users[indexPath.item]
}

override func numberOfItems(_ section: Int) -> Int {
    return users.count
}

}

这是我的手机,你可以看到我已经成功打印了名字。您可以看到我在哪里发表评论以查看我的问题。

import LBTAComponents
import MapKit
import CoreLocation

class UserCell: DatasourceCell, CLLocationManagerDelegate, MKMapViewDelegate  {


let distanceSpan: Double = 500


 override var datasourceItem: Any? {
    didSet {
        guard let user = datasourceItem as? User else { return }
        nameLabel.text = user.name
        MapView.setCenter(user.position, animated: false)


        }


   }

let nameLabel: UILabel = {
    let label = UILabel()
    label.font = UIFont.boldSystemFont(ofSize: 14)
    return label

}()

let MapView: MKMapView = {
    let map = MKMapView()
    map.isZoomEnabled = false
    map.isScrollEnabled = false
    map.isUserInteractionEnabled = false
    return map

}()
阿尼尔·库卡德亚

你的纬度和经度应该是一种

CLLocationCoordinate2D

不是

CLLocationDegrees

.

否则,您只能定义一个 CLLocationCoordinate2D 类型的变量。

喜欢

var location = CLLocationCoordinate2D() 

location.coordinate.latitude = "-72.455412"
location.coordinate.longitude = "40.005165"

同样的方式你可以检索经纬度。只需更改您的模型变量。我想应该没问题。

您的代码中的其他内容看起来不错。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Swift 3中获取地图上的路线

使用Openlayers 3在地图上单击时坐标错误

从Firestore Swift在Google地图上显示多个位置

D3 DataMaps(或jvectormap):如何通过坐标将自定义对象放置在地图上

swift 3 google maps - 如何更新地图上的标记

d3.js在地图上绘制机场地图点,并在不同文件上绘制坐标

显示文字并通过d3地图上的超链接直接显示

如何从PFGeopoint检索位置-(Parse.com和Swift)并使用Xcode 6.2在地图上显示位置

如何“当我打开ViewController时在Google地图上显示我的当前位置?” 在Swift中?

在带有MapKit的地图上通过图钉显示自定义位置(Swift)

AngularJS在地图上显示用户的预定义坐标

GeoJSON要素坐标未显示在OpenLayers地图上

UIBarButtonItem未显示Swift 3

使用D3.js和GeoJson在地图上的州显示一些文本

仅在一张地图上显示的OpenLayer3叠加层

如何在地图上的3s平面中显示一条线?

Gmap3从数据库显示地图上所有可用的标记吗?

获取世界环绕时在Google地图上显示的总纬度/经度-Javascript v3 API

如何在用 d3 绘制的 SVG 地图上显示国名标签?

OpenLayers 3-在地图上显示文本,相对于缩放的文本大小

在Google地图上显示OpenStreetMap边界(使用v3 API)

并非所有d3点都在传单地图上显示正确的位置

Ionic 3-无法点击显示在Google地图上方的警报对话框

如何在D3中的地图上的鼠标悬停时显示多个值?

d3.js v5:无法获取数据点以在美国地图上显示

在D3js中的一张地图上进行Mousover时,如何显示多张地图的工具提示

Swift 3 NSNotificationCenter键盘将显示/隐藏

Swift 3:显示URL中的图片

在 NSImageView 中显示 gif - Swift 3 - Mac