【问题标题】:Directions app ambiguous member路线应用模棱两可的成员
【发布时间】:2017-01-06 23:45:28
【问题描述】:

我有一个路线 ap,但我对“directionsusinggoogle”错误的成员感到模棱两可。它使用 google places api 来计算方向等。这是我的代码。这是错误的图像。

  @IBAction func ClickToGo(_ sender: AnyObject) {
    if isValidPincode() {
        mapManager.directionsUsingGoogle(from: txtFrom.text!, to: txtTo.text!) { (route,directionInformation, boundingRegion, error) -> () in

            if(error != nil){
                print(error)
            }
            else{
                let pointOfOrigin = MKPointAnnotation()
                pointOfOrigin.coordinate = route!.coordinate
                pointOfOrigin.title = directionInformation?.object(forKey: "start_address") as! NSString as String
                pointOfOrigin.subtitle = directionInformation?.object(forKey: "duration") as! NSString as String

                let pointOfDestination = MKPointAnnotation()
                pointOfDestination.coordinate = route!.coordinate
                pointOfDestination.title = directionInformation?.object(forKey: "end_address") as! NSString as String
                pointOfDestination.subtitle = directionInformation?.object(forKey: "distance") as! NSString as String

                let start_location = directionInformation?.object(forKey: "start_location") as! NSDictionary
                let originLat = start_location.object(forKey: "lat")?.doubleValue
                let originLng = start_location.object(forKey: "lng")?.doubleValue

                let end_location = directionInformation?.object(forKey: "end_location") as! NSDictionary
                let destLat = end_location.object(forKey: "lat")?.doubleValue
                let destLng = end_location.object(forKey: "lng")?.doubleValue

                let coordOrigin = CLLocationCoordinate2D(latitude: originLat!, longitude: originLng!)
                let coordDesitination = CLLocationCoordinate2D(latitude: destLat!, longitude: destLng!)

                pointOfOrigin.coordinate = coordOrigin
                pointOfDestination.coordinate = coordDesitination
                if let web = self.drawMap {
                    DispatchQueue.main.async {
                    self.removeAllPlacemarkFromMap(shouldRemoveUserLocation: true)
                    web.add(route!)
                    web.addAnnotation(pointOfOrigin)
                    web.addAnnotation(pointOfDestination)
                    web.setVisibleMapRect(boundingRegion!, animated: true)
                    print(directionInformation)
                    self.tableData = directionInformation!
                    }
                }
            }
        } }
}

【问题讨论】:

标签: ios iphone swift swift3


【解决方案1】:

假设您使用 https://github.com/varshylmobile/MapManager/blob/master/MapManager.swift 并将其转换为 Swift 3,则 API 具有以下签名:

func directionsUsingGoogle(from:NSString, to:NSString,
    directionCompletionHandler:DirectionsCompletionHandler)

func directionsUsingGoogle(from:CLLocationCoordinate2D, to:CLLocationCoordinate2D,
    directionCompletionHandler:DirectionsCompletionHandler)

func directionsUsingGoogle(from:CLLocationCoordinate2D, to:NSString,
    directionCompletionHandler:DirectionsCompletionHandler)

注意NSString,因此:

mapManager.directionsUsingGoogle(
    from: txtFrom.text! as NSString,
    to: txtTo.text! as NSString,
    directionCompletionHandler: {(
        _ route:MKPolyline?,
        _ directionInformation:NSDictionary?,
        _ boundingRegion:MKMapRect?,
        _ error:String?) in
        ...
    }
)

【讨论】:

  • OT,但我很好奇为什么编译器消息是“模棱两可的成员...”而不是“没有字符串类型的成员,字符串...”之类的东西
  • swift 建筑师我想知道你能不能帮我做点别的事情
  • 当然 - 在 Stack Overflow 上发布您的问题并在此处放置指向它的链接
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-03
  • 1970-01-01
相关资源
最近更新 更多