[英]How to pass latitude-longitude to Google Maps JavaScript API v3 Directions service?
我想在我的Java應用程序中使用Google Maps JavaScript API v3 。 為此,我使用http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false網址創建了HttpGet對象。
我得到了正確的答案,但我沒有通過電台名稱 ,而是希望通過電台的緯度 - 經度 。
可以在Here找到文檔
如何將緯度 - 經度傳遞給此服務?
編輯:
當我將URL指定為 - http://maps.googleapis.com/maps/api/directions/json?origin=Jackson+Av&destination=Prospect+Av&sensor=false時,我得到了正確的回復,但當我將URL作為 -
您可以創建網址,如下所示,
double lat1 = 40.74560;
double lon1 = -73.94622000000001;
double lat2 = 46.59122000000001;
double lon2 = -112.004230;
String url = "http://maps.googleapis.com/maps/api/directions/json?";
List<NameValuePair> params = new LinkedList<NameValuePair>();
params.add(new BasicNameValuePair("origin", lat1 + "," + lon1));
params.add(new BasicNameValuePair("destination", lat2 + "," + lon2));
params.add(new BasicNameValuePair("sensor", "false"));
String paramString = URLEncodedUtils.format(params, "utf-8");
url += paramString;
HttpGet get = new HttpGet(url);
請檢查您是否提供正確的地理坐標
只需使用數字表示緯度,經度用逗號分隔:例如51,0
。 確保沒有空格。
http://maps.googleapis.com/maps/api/directions/json?origin=51,0&destination=51.5,-0.1&sensor=false
v3 API的文檔說明了google.maps.LatLng或字符串。 對於地理位置,請創建並傳入google.maps.LatLng; 對於地址,傳入一個字符串。
origin: LatLng | String,
destination: LatLng | String,
並在參考
destination LatLng|string Location of destination. This can be specified as either a string to be geocoded or a LatLng. Required.
origin LatLng|string Location of origin. This can be specified as either a string to be geocoded or a LatLng. Required.
並為航點 :
location LatLng|string Waypoint location. Can be an address string or LatLng. Optional.
var request = {
origin: "33.661565,73.041330",
destination: "33.662502,73.044061",
travelMode: google.maps.TravelMode.DRIVING
};
這很好用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.