【问题标题】:Unable to create apple map address link with latitude and longitude in swift无法在swift中创建带有经纬度的苹果地图地址链接
【发布时间】:2020-11-25 13:25:26
【问题描述】:

我正在尝试创建带有经纬度的苹果地图地址链接

我试过这样:

  let addrLoction = addressModel[indexPath.row]

                   let coord = addrLo.location
                   latitude = coord?.latitude
                   longitude = coord?.longitude

    
   let mapAddr =  "http://maps.apple.com/?q={latitude},{longitude}" 

出现错误:

运算符后的预期表达式

例如:像android app goole maps地址链接,我需要apple map地址链接

【问题讨论】:

  • 你在哪几行得到错误?
  • @sp4c38 这里let mapAddr = "http://maps.apple.com/?q={latitude},{longitude}"
  • 将最后一行更改为let mapAddr = "http://maps.apple.com/?q=\(latitude),\(longitude)" 有帮助吗?

标签: swift apple-maps


【解决方案1】:

两个问题:

  1. latitudelongitude 是可选的。即使字符串插值语法是正确的,你也会得到类似"Optional(45.000)" 的东西。使用可选绑定。

  2. 字符串插值语法错误,是\(value)

    if let coord = addrLo.location {
        let latitude = coord.latitude
        let longitude = coord.longitude
    
        let mapAddr = "https://maps.apple.com/?q=\(latitude),\(longitude)" 
        // ...
    }
    

并且URL方案应该是https

【讨论】:

    猜你喜欢
    • 2013-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-15
    • 1970-01-01
    • 2012-09-30
    • 1970-01-01
    相关资源
    最近更新 更多