簡體   English   中英

如何在Google Elevation API中使用坐標數組?

[英]How to use an array of coordinates with Google Elevation API?

我正在嘗試在一個請求中向Google Elevation API發送多個位置,您應該能夠每個請求最多發送512個位置。 他們的文檔說要使用:用管道字符('|')分隔的坐標數組:locations = 40.714728,-73.998672 | -34.397,150.644,但我得到的錯誤是:原因:java.net.URISyntaxException:非法索引99中查詢的字符: https : //maps.googleapis.com/maps/api/elevation/json?locations=51.606013718523265 ,-8.432384161819547| 51.606031961540985 ,-8.432374430210215| 51.60607166348032 ,-8.432334651837888| 51.60610446039263 ,-8.4322494395575 & key如果我只發送一個點就可以。 有人告訴我使用豎線('|')字符,但不會接受。 我的代碼是

 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編碼。 根據有關Web服務文檔

建立有效的URL

您可能會認為“有效” URL是不言而喻的,但事實並非如此。 例如,在瀏覽器的地址欄中輸入的URL可以包含特殊字符(例如“上海+中國”); 瀏覽器需要在傳輸之前在內部將這些字符轉換為不同的編碼。 同樣,生成或接受UTF-8輸入的任何代碼都可能會將帶有UTF-8字符的URL視為“有效”,但在將這些字符發送到Web服務器之前,也需要進行翻譯。 此過程稱為URL編碼。

我們需要翻譯特殊字符,因為所有URL都必須符合W3統一資源標識符規范所指定的語法。 實際上,這意味着URL必須僅包含ASCII字符的一個特殊子集:熟悉的字母數字符號和一些保留的字符,以用作URL中的控制字符。

必須編碼的一些常見字符是:

Unsafe character   Encoded value
|                  %7C

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM