Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Google Elevation API中使用坐标数组?_Java_Google Maps - Fatal编程技术网

Java 如何在Google Elevation API中使用坐标数组?

Java 如何在Google Elevation API中使用坐标数组?,java,google-maps,Java,Google Maps,我试图在一个请求中向Google Elevation API发送多个位置,每个请求最多可以发送512个位置。他们的文件说要使用: 使用管道(“|”)字符分隔的坐标数组:位置=40.714728,-73.998672 |-34.397150.644 但我要找回错误: 原因:java.net.URISyntaxException:索引99处的查询中存在非法字符: 如果我只发送一个点就行了。我被告知使用管道(“|”)字符,但它不会接受它。我的代码是 position = ellipsePositio

我试图在一个请求中向Google Elevation API发送多个位置,每个请求最多可以发送512个位置。他们的文件说要使用: 使用管道(“|”)字符分隔的坐标数组:位置=40.714728,-73.998672 |-34.397150.644 但我要找回错误: 原因:java.net.URISyntaxException:索引99处的查询中存在非法字符: 如果我只发送一个点就行了。我被告知使用管道(“|”)字符,但它不会接受它。我的代码是

 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;
    }
 }   

有人能帮忙吗?

您需要对查询字符串中的任何“不安全”字符进行URL编码。根据

建立有效的URL

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

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

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

不安全字符编码值 |%7C 如果我从您的中删除了(无效)密钥,它在浏览器中对我有效。您是否调查了字符串的URL编码?谢谢,我将“|”替换为“%7C”,它可以工作
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);
Unsafe character Encoded value | %7C