2016-07-07 9 views
1
@Grab('com.github.groovy-wslite:groovy-wslite:1.1.2') 
import wslite.rest.* 

String key = 'my-key' 
def client = new RESTClient('https://maps.googleapis.com/maps/api/directions/') 
def response = client.get(path: 'xml', 
query: [ 
    origin: 'Disneyland', 
    destination: 'Universal Studios Hollywood', 
    sensor: 'false', 
    mode: 'driving', 
    key: 'my-key' 
    ]) 

println response.DirectionsResponse.status 
println response.DirectionsResponse.summary 

RESTをGroovyで使用してGoogle APIの指示を使用しようとしていますが、response.DirectionsResponseから印刷できないようです。 nullまたはエラーを出力します。何か不足していますか?私はどこでも答えを探してみましたが、見つけられませんでした。Google Maps Directions API GroovyでRESTを使用する

答えて

1

4つの問題があると考えてください。あなたは、これは、文書のルート要素であるとして、あなたはDirectionsResponseを必要としない応答

  • の解析されたXMLコンテンツを取得するためにresponse.xmlを使用する必要がGETクエリ
  • accept: ContentType.XMLを渡す必要が

    1. summaryノードroute

    次の内側にある(response.xmlによってすでにに指し示さ) hould作業:

    @Grab('com.github.groovy-wslite:groovy-wslite:1.1.2') 
    import wslite.rest.* 
    
    def client = new RESTClient("https://maps.googleapis.com/") 
    def response = client.get(
        path: "/maps/api/directions/xml", 
        accept: ContentType.XML, 
        query: [ 
         origin: 'Disneyland', 
         destination: 'Universal Studios Hollywood', 
         sensor: 'false', 
         mode: 'driving', 
         key: 'AIzaSyBioD99qXv43yHLb9EuxemPeMHA1drpiqw' 
        ]) 
    
    println response.xml.status 
    println response.xml.route.summary 
    

    PS:あなたは今、その1つの公衆を作ったとして、あなたはおそらく、新しいキーを生成したい(あなたが自由層にしている場合)、非常に多くの人々があなたの手当を使用することができ、またはあなたのお金(あなたがそれを支払った場合)

  • 関連する問題