我遇到了一个奇怪的问题,
当我从 web 浏览器或 java 命令行在 url 下运行时
我得到以下结果。
{
"destination_addresses" : [ "Storås Industrigata 20, 424 69
Angered, Sweden" ],
"origin_addresses" : [ "Gothenburg, Sweden" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "10.4 km",
"value" : 10388
},
"duration" : {
"text" : "15 mins",
"value" : 924
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
但是当我从 glassfish 服务器运行相同的 url 时,我的意思是发送一个 http请求来自 表单提交我得到以下奇怪的响应
{ "destination_addresses" : [ "" ],
"origin_addresses" : [ "Gothenburg, Sweden" ],
"rows" : [
{
"elements" : [
{
"status" : "NOT_FOUND"
}
]
}
],
"status" : "OK"
}
在这种情况下,请不要将 destination_addresses 和 status 设为空 NOT_FOUND。
我用来获取响应的Java代码是
private String getResponse(String URL) throws Exception {
InputStream stream = new URL(URL).openStream();
byte[] array = new byte[stream.available()];
stream.read(array);
return new String(array);
}
请指导我解决这个问题,
谢谢....
最佳答案
使用 https
除非谷歌不会让您的软件连接。
和 获取一个 api key 。
读这个: https://developers.google.com/maps/documentation/distance-matrix/start
https://maps.googleapis.com/maps/api/distancematrix/json?origins=416%2063,Sweden&destinations=424%2069,Stor%C3%A5s%20Industrigatan%2020,Angered,G%C3%B6teborg&sensor=false&key=YOUR_API_KEY
请务必将 YOUR_API_KEY 替换为您的实际 API key
关于java - 谷歌距离矩阵api奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10373227/