javagoogle距离矩阵api
我在这里面临一个奇怪的问题
当我从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"
}
在这种情况下,请不要将目标地址为空,并且状态为 没有找到
我用来获取响应的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);
}
请引导我解决这个问题
谢谢
# 1 楼答案
在Java中使用距离矩阵API时,我遇到了类似的问题。在我的请求中设置语言似乎可以让它工作:
# 2 楼答案
使用https
除非谷歌不让你的软件连接
及 获取api密钥
请阅读以下内容: https://developers.google.com/maps/documentation/distance-matrix/start
确保用实际的API密钥替换您的API密钥