简体   繁体   English

Google Maps Directions API显示错误的方向

[英]Google Maps Directions API showing wrong directions

I am using the Google Maps API and the Google Maps Directions API for tracking the journey of a pilgrimage. 我正在使用Google Maps API和Google Maps Directions API跟踪朝圣之旅。 My travel mode is walking and I have 8 waypoints placed along the way (Google doesn't allow you to add more for free) . 我的出行方式是步行,沿途放置了8个航点(Google不允许您免费添加更多)

The problem is that Google Maps is taking an odd unsought detour from the original path. 问题在于,Google Maps正在沿着原始路径进行奇怪的未请求的绕行。 I set up LatLng coordinates as waypoints accordingly to fix the problem, but the API remains stubborn on its resolve to take me 200 km away from the path and back again... 我相应地将LatLng坐标设置为航点,以解决问题,但API仍然坚决地决心要使我离开路径200公里,然后再次返回...

I have attached a screenshot of the app with this question. 我已附上该应用程序的屏幕截图,并附带了此问题。 As you can see, in the bottom right corner, Google Maps takes a detour. 如您所见,在右下角,Google地图绕道而行。 How do I fix the problem? 我该如何解决该问题? Thank You. 谢谢。 在此处输入图片说明

Here's some code: 这是一些代码:

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

Fixed the Problem. 解决了问题。 There was an alternative place with the same name as one of my way-points. 另一个地方与我的路标之一同名。 I changed the way-point in my URL from a name to specific Lat-Long Coordinates and that solved the problem for me. 我将网址中的航点从名称更改为特定的经纬度坐标,这为我解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM