为方向创建折线 - Akexorcist Google Map Directions API

时间:2016-11-30 08:07:42

标签: android google-maps-android-api-2

我在Akexorcist的谷歌地图方向api库上为方向绘制折线时遇到问题。 即时通讯使用akexorcist库你可以在这里得到它:

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

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

我有两个latlng对象(原点和目的地),我只需要创建一个多边形线来显示使用他的库的方向。 错误显示:

  

java.lang.IndexOutOfBoundsException:索引1无效,大小为0

这是代码:

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

                    }
                });
    }

和onMapReady()

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

完整错误日志:

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)

归属主人。帮帮我谢谢

0 个答案:

没有答案