我正在使用Google Maps API和Google Maps Directions API来跟踪朝圣之旅。 我的旅行模式是步行,我沿途有8个航点(谷歌不允许你免费添加更多)。
问题在于谷歌地图正在从原始路径中走出一条奇怪的未被绕道的路。我将LatLng坐标设置为相应的航路点以解决问题,但是API仍然顽固地决定将我带离路径200公里再回来......
我已经附上了这个问题的应用截图。正如您所看到的,在右下角,谷歌地图绕道而行。我该如何解决这个问题?谢谢。
这里有一些代码:
String url = "https://maps.googleapis.com/maps/api/directions/json?origin=18.6769503," +
"73.8945701&destination=17.6774444,75.3329239&mode=walking&waypoints=" +
"via:Saswad,MH|via:Jejuri,MH|via:Natepute,MH|" +
"via:Velapur,MH|via:Bhandishegaon,MH|via:Wakhari,MH|" +
"via:17.685236,75.287492|via:17.682496,75.304931&" +
"key=MY_API_KEY";
RequestQueue requestQueue = Volley.newRequestQueue(this);
StringRequest jsonObjectRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("Json Data", "Successfully Retrieved - Starting Parse Process");
mapJsonData = response;
try {
parseJsonData(mapJsonData);
} catch (JSONException e) {
e.printStackTrace();
}
PolylineOptions polyOptions = new PolylineOptions().geodesic(true).
color(Color.RED).
width(10);
polyOptions.add(dnyaneshwarOrigin);
for (int i = 0; i < polyPoints.size(); i++) {
polyOptions.add(polyPoints.get(i));
}
polyOptions.add(vitthalMandir);
gMap.addPolyline(polyOptions);
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(dnyaneshwarOrigin);
builder.include(vitthalMandir);
mapLayout.getViewTreeObserver().addOnGlobalLayoutListener
(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
LatLngBounds bounds = builder.build();
gMap.animateCamera(CameraUpdateFactory.newLatLngBounds
(bounds, 20));
}
});
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Response Error", "Could Not Retrieve Json Data");
Toast.makeText(MapActivity.this, "Error Retrieving Json Data",
Toast.LENGTH_SHORT).show();
}
});
Log.i("Request Queue", "Sending Json Request");
requestQueue.add(jsonObjectRequest);
答案 0 :(得分:0)
修正了问题。有一个替代的地方与我的一个路点同名。 我将网址中的路径从名称更改为特定的Lat-Long坐标,这为我解决了问题。