2016-10-15 6 views
1

Google지도 장소 API와 오류 :얻기 나는 아래의 코드를 실행하기 위해 노력하고있어 lookUpPlaceID

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

답변

5

이런 식으로 뭔가가 당신을 위해 작동합니다 :

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

그게 효과가 있었고, 내가 뭘 잘못하고 있었는지 설명해 주시겠습니까? – Khattab

관련 문제