1

https://developers.google.com/maps/documentation/distancematrix/から

私が入力した場合:

http://maps.googleapis.com/maps/api/distancematrix/json?origins=Hickory+NC&destinations=Niagra+Falls+NY&sensor=false&units=imperial

それから私は得る:

{
   "destination_addresses" : [ "Niagara Falls, NY, USA" ],
   "origin_addresses" : [ "Hickory, NC, USA" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "667 mi",
                  "value" : 1072719
               },
               "duration" : {
                  "text" : "11 hours 21 mins",
                  "value" : 40835
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

しかし、このコマンドを発行すると、次のようになります。

<cfhttp method="get" result="myContent" url="http://maps.googleapis.com/maps/api/distancematrix/json">
    <cfhttpparam type="url" name="origins" value="Hickory+NC">
    <cfhttpparam type="url" name="destinations" value="Niagra+Falls+NY">
    <cfhttpparam type="url" name="sensor" value="false">
    <cfhttpparam type="url" name="units" value="imperial">
</cfhttp>
<cfdump var="#myContent#">

次に、StatusCode = 200OKの構造を取得しますが、Text=NOです。

4

1 に答える 1

2

getAsBinary="never"cfhttpに追加

<cfhttp method="get" result="myContent" url="http://maps.googleapis.com/maps/api/distancematrix/json" getAsBinary="never">
    <cfhttpparam type="url" name="origins" value="Hickory+NC">
    <cfhttpparam type="url" name="destinations" value="Niagra+Falls+NY">
    <cfhttpparam type="url" name="sensor" value="false">
    <cfhttpparam type="url" name="units" value="imperial">
</cfhttp>
<cfdump var="#myContent#">

myContent.FileContent でこれを返します

 {
    "destination_addresses": ["Niagara Falls, NY, USA"],
    "origin_addresses": ["Hickory, NC, USA"],
    "rows": [{
        "elements": [{
            "distance": {
                "text": "667 mi",
                "value": 1072719
            },
            "duration": {
                "text": "11 hours 21 mins",
                "value": 40835
            },
            "status": "OK"
        }]
    }],
    "status": "OK"
}
于 2012-08-31T08:36:22.037 に答える