Google maps api 3 如何从GoogleMapsAPI处理json
从 如果我进入:Google maps api 3 如何从GoogleMapsAPI处理json,google-maps-api-3,coldfusion,Google Maps Api 3,Coldfusion,从 如果我进入: 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" : [ "H
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的结构。将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#">
我想自己试试,但我在打电话。尽量不要在param标记中对您的值进行URL编码。只需使用空格,而不是+,然后查看是否得到不同的结果。确保您正在查看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"
}