【问题标题】:Getting Error With Google Maps Places API with lookUpPlaceID使用 lookUpPlaceID 的 Google Maps Places API 出错
【发布时间】:2016-10-15 23:52:33
【问题描述】:

我正在尝试运行以下代码:

func mapView(_ mapView: GMSMapView, didTapPOIWithPlaceID placeID: String, name: String, location: CLLocationCoordinate2D) {
        print("You tapped \(name): \(placeID), \(location.latitude)/\(location.longitude)")

        infoMarker.snippet = placeID
        infoMarker.position = location
        infoMarker.title = name
        infoMarker.opacity = 0;
        infoMarker.infoWindowAnchor.y = 1
        infoMarker.map = mapView
        mapView.selectedMarker = infoMarker

        placesClient!.lookUpPlaceID(placeID, callback: { (place: GMSPlace?, error: NSError?) -> Void in
            if let error = error {
                print("lookup place id query error: \(error.localizedDescription)")
                return
            }

            if let place = place {
                print("Place name \(place.name)")
                print("Place address \(place.formattedAddress)")
                print("Place placeID \(place.placeID)")
                print("Place attributions \(place.attributions)")
            } else {
                print("No place details for \(placeID)")
            }
        } as! GMSPlaceResultCallback)
    }

只要 lookUpPlaceID 行运行,它就会抛出异常:

EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

【问题讨论】:

    标签: swift3 google-places-api google-maps-sdk-ios


    【解决方案1】:

    这样的东西应该适合你:

    placesClient.lookUpPlaceID(placeId, callback: { (place, error) -> Void in
      if let error = error {
        print("lookup place id query error: \(error.localizedDescription)")
        return
      }
    
      if let place = place {
        print("Place name \(place.name)")
        print("Place address \(place.formattedAddress)")
        print("Place placeID \(place.placeID)")
        print("Place attributions \(place.attributions)")
      } else {
        print("No place details for \(placeID)")
     }
    })
    

    【讨论】:

    • 成功了,你能解释一下我做错了什么吗?
    猜你喜欢
    • 2012-05-10
    • 2020-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-18
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多