Google Maps API请求

MK1000

我正在做一个项目,我希望向Google地图发送请求。我需要从Google接收从一个位置到另一个位置的路径。这在“ Web服务”区域中。

必须在Java中完成。

根据我在google maps api描述中看到的内容,google对任何请求的响应均为XML格式。

那里没有问题,因为为此,我们可以使用XPath和任何其他工具进行解析。

因此,我只需要如何将该请求发送到Java中的google API?如果您能解释每个步骤,那就太好了。

谢谢您的耐心:)

安德烈亚斯·布鲁内特(Andreas Brunnet)

好吧,我正在研究一个模拟项目(使用Mapquest而不是Google)。我只是这样使用HttpConnection:

String requestString = buildURL("Washington", "New York");
URL url = new URL(requestString);
HttpsConnection conn = (HttpsConnection) url.openConnection();
InputStream stream = conn.getInputStream();

只需使用API​​提供给您的普通请求网址即可。使用StringBuilder构建带有诸如起点和终点之类的参数的URL,例如

public String buildURL(String origin, String destination)
{
StringBuilder urlBuilder = new StringBuilder();
urlBuilder("https://maps.googleapis.com/maps/api/directions/json?");
urlBuilder("origin=");
urlBuilder(origin);

urlBuilder("&destination=");
urlBuilder(destination);

urlBuilder("&key=");
urlBuilder(MY_KEY);

return urlBuilder.toString();
}

最后一步是将流传递到XMLParser。您还可以在Connection上进行响应代码检查,以处理错误的请求等错误。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Google Maps API for Work客户-API请求

来自分类Dev

Google Maps API距离矩阵请求

来自分类Dev

Google Maps API GET请求失败,出现跨域错误

来自分类Dev

非法字符“ |” 应Google Maps API V2请求

来自分类Dev

Python:对Google Maps API的请求-握手问题

来自分类Dev

NodeJS请求模块Google Maps GeoCode API发布

来自分类Dev

使用 Google Maps API 延迟每个请求的 Ajax 函数

来自分类Dev

Google Maps API RefererNotAllowedError

来自分类Dev

Google Maps API DeletedApiProjectMapError

来自分类Dev

Google Maps Api许可

来自分类Dev

Google Maps Api

来自分类Dev

Google Maps REST API

来自分类Dev

Google Maps Directions API

来自分类Dev

Google Maps API参数

来自分类Dev

Google Maps API在有效请求中返回“无效请求”

来自分类Dev

Google Maps API在有效请求中返回“无效请求”

来自分类Dev

Google Maps Javascript API与Google Maps Embed API

来自分类Dev

缺少Google Maps RouteBoxer API

来自分类Dev

异步加载Google Maps API

来自分类Dev

动态加载Google Maps API

来自分类Dev

Google Maps API的JavaScript框架

来自分类Dev

Google Maps API搜索限制

来自分类Dev

Google Maps Api机场搜索

来自分类Dev

Google Maps Geocoding的API密钥

来自分类Dev

Google Maps API密钥错误

来自分类Dev

Google Maps Api:infowindow与infobubble?

来自分类Dev

Google Maps API停止显示

来自分类Dev

Google Maps API标记刷新

来自分类Dev

更改Google Maps API语言