代码之家  ›  专栏  ›  技术社区  ›  Khattab

Google Maps Places API使用lookUpPlaceID时出错

  •  1
  • Khattab  · 技术社区  · 8 年前

    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)
    

    enter image description here

    1 回复  |  直到 8 年前
        1
  •  5
  •   Jeffery Thomas    7 年前

    这样的东西应该对你有用:

    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)")
     }
    })