0

i am having a problem drawing a polyline for directions on Akexorcist's google map directions api library. im using akexorcist library you can get it here:

Akexorcist Website: http://www.akexorcist.com/2015/12/google-direction-library-for-android-en.html

Github: https://github.com/akexorcist/Android-GoogleDirectionLibrary

i have a two latlng objects (origin and destination) and i just need to create a poly line to display directions using his library. error shows :

java.lang.IndexOutOfBoundsException: Invalid index 1, size is 0

here's the code:

private void ListingNearbyDirection(final LatLng Origin, final LatLng Destination){
        String serverKey = "AIzaSyAGpF1Jedi8EEliwUPk************";

        GoogleDirection.withServerKey(serverKey)
                .from(Origin)
                .to(Destination)
                .transportMode(TransportMode.DRIVING)
                .alternativeRoute(true)
                .execute(new DirectionCallback() {
                    @Override
                    public void onDirectionSuccess(Direction direction, String rawBody) {
                        mMap.addMarker(new MarkerOptions().position(Origin));
                        mMap.addMarker(new MarkerOptions().position(Destination));
                        mMap.animateCamera(CameraUpdateFactory.newLatLng(Origin));
                        moveToCurrentLocation(Origin);

                        ArrayList<LatLng> directionPositionList = direction.getRouteList().get(0).getLegList().get(0).getDirectionPoint();
                        PolylineOptions polylineOptions = DirectionConverter.createPolyline(getApplicationContext(), directionPositionList, 5, Color.YELLOW);
                        mMap.addPolyline(polylineOptions);
                    }

                    @Override
                    public void onDirectionFailure(Throwable t) {

                    }
                });
    }

and on onMapReady()

LatLng origin = getLocationFromAddress(this, address);
            LatLng destination = new LatLng(Double.parseDouble(myLatitude), Double.parseDouble(myLongitude));
            ListingNearbyDirection(origin, destination);

full error log:

12-01 00:28:16.031 19892-19892/? E/AndroidRuntime: FATAL EXCEPTION: main
12-01 00:28:16.031 19892-19892/? E/AndroidRuntime: Process: homeseek.app.android.capstonehomeseek, PID: 19892
12-01 00:28:16.031 19892-19892/? E/AndroidRuntime: java.lang.IndexOutOfBoundsException: Invalid index 1, size is 0
12-01 00:28:16.031 19892-19892/? E/AndroidRuntime:     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
12-01 00:28:16.031 19892-19892/? E/AndroidRuntime:     at java.util.ArrayList.get(ArrayList.java:308)
12-01 00:28:16.031 19892-19892/? E/AndroidRuntime:     at homeseek.app.android.capstonehomeseek.PropertyLocationMap$3.onDirectionSuccess(PropertyLocationMap.java:174)
12-01 00:28:16.031 19892-19892/? E/AndroidRuntime:     at com.akexorcist.googledirection.request.DirectionRequest$1.onResponse(DirectionRequest.java:108)
12-01 00:28:16.031 19892-19892/? E/AndroidRuntime:     at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:66)
12-01 00:28:16.031 19892-19892/? E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
12-01 00:28:16.031 19892-19892/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
12-01 00:28:16.031 19892-19892/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
12-01 00:28:16.031 19892-19892/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5451)
12-01 00:28:16.031 19892-19892/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
12-01 00:28:16.031 19892-19892/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
12-01 00:28:16.031 19892-19892/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

credits to the owner. help me thanks

4
  • I think direction.getRouteList().get(0).getLegList().get(0).getDirectionPoint(); here only error possibilities can you post full error log
    – Rajesh
    Nov 30, 2016 at 10:56
  • i just updated my question Nov 30, 2016 at 16:33
  • use try catch in directionPostionList
    – Rajesh
    Nov 30, 2016 at 17:56
  • I think it might be some problem that occurred in Direction API response. @JarvisMillan asked me in Facebook Page then share the location that made the problem but it works properly when I tested it. So I updated the library to version 1.0.5 that can enable the log from Direction API to check the request/response with this command GoogleDirectionConfiguration.getInstance().setLogEnabled(true); So I waiting the response from him now.
    – Akexorcist
    Dec 1, 2016 at 2:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.