如何使用Google Elevation API的坐标数组



我试图在一个请求中向Google Elevation API发送多个位置,每个请求最多可以发送512个位置。他们的文件规定使用:使用竖线('|')字符分隔的坐标数组:位置=40.714728,-73.9998672|-34.397150.644但我正在恢复错误:引起原因:java.net.URISyntaxException:索引99处的查询中存在非法字符:https://maps.googleapis.com/maps/api/elevation/json?locations=51.606013718523265,-8.432384161819547|51.606031961540985,-8.4323 74430210215|51.60607166348032,-8.432.334651837888|51.60610446039263,-8.4322494395575&key=myAPIkey如果我只发送一个点,它就会起作用。我被告知要使用管道('|')字符,但它不接受。我的代码是

 position = ellipsePositions.get(index1);              
 longitude = position.getLongitude();
 latitude = position.getLatitude();
 APIstring = latitude + "," + longitude;
 for (int index = 1; index < indexList.size(); index++)
 {
    if (ellipsePositions.get(index) != null)
    { 
       position = ellipsePositions.get(index);              
       longitude = position.getLongitude();
       latitude = position.getLatitude();
       APIstring = APIstring + "|" +  latitude + "," + longitude;
    }
 }   

WebResource webResource =   client.resource("https://maps.googleapis.com/maps/api/elevation/json?locations="+ APIstring + "&key=myAPIkey");
ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
String data = response.getEntity(String.class);

有人能帮忙吗?

您需要对任何"不安全";查询字符串中的个字符。根据网络服务上的文档

建立有效的URL

你可能会认为;有效的";URL是不言而喻的,但事实并非如此。例如,在浏览器的地址栏中输入的URL可以包含特殊字符(例如;上海+中國");浏览器需要在传输之前将这些字符内部翻译成不同的编码。同样,任何生成或接受UTF-8输入的代码都可能将具有UTF-8字符的URL视为"UTF-8";有效";,但也需要在将这些字符发送到网络服务器之前对其进行翻译。这个过程称为URL编码。

我们需要翻译特殊字符,因为所有URL都需要符合W3统一资源标识符规范指定的语法。实际上,这意味着URL必须只包含ASCII字符的一个特殊子集:熟悉的字母数字符号,以及一些保留字符,用作URL中的控制字符。

必须编码的一些常见字符有:

不安全字符编码值|%7C

最新更新