简体   繁体   中英

Google Maps for Android - Polyline crashing app

I am importing geoJSON data from .jsons files. It works very well with some files but not with others. I thought my files had problems but I tested them on geojson lint as well as geojson.io without issues.

Here is the stack:

FATAL EXCEPTION: main
Process: com.example.andrea.blank_test, PID: 8780
java.lang.NoSuchMethodError: No virtual method isClickable()Z in class Lcom/google/android/gms/maps/model/PolylineOptions; or its super classes (declaration of 'com.google.android.gms.maps.model.PolylineOptions' appears in /data/data/com.example.andrea.blank_test/files/instant-run/dex/slice-dependencies_2c16afb1f7a3d667bc9f1bb08f04b953876fdec1-classes.dex)
    at com.google.maps.android.geojson.GeoJsonLineStringStyle.toPolylineOptions(GeoJsonLineStringStyle.java:167)
    at com.google.maps.android.geojson.GeoJsonRenderer.addLineStringToMap(GeoJsonRenderer.java:297)
    at com.google.maps.android.geojson.GeoJsonRenderer.addFeatureToMap(GeoJsonRenderer.java:238)
    at com.google.maps.android.geojson.GeoJsonRenderer.addFeature(GeoJsonRenderer.java:166)
    at com.google.maps.android.geojson.GeoJsonRenderer.addLayerToMap(GeoJsonRenderer.java:117)
    at com.google.maps.android.geojson.GeoJsonLayer.addLayerToMap(GeoJsonLayer.java:112)

Here is my very simple code

int d = R.raw.geojson;
try {
    GeoJsonLayer layer = new GeoJsonLayer(map, d,
            getApplicationContext());
    layer.addLayerToMap();
} catch (Exception ex){
    Log.e("hey", ex.toString());
}

And here is one of my JSONs causing that bug

build.gradle (project) and build.gradle(app)

Any idea is welcome

The problem is that the PolylineOptions implementation in Google Play Services version 8.3.0 does not include the isClickable() method.

It has been added in version 8.4.0, and if you take a look at the GeoJsonLineStringStyle.java history on GitHub you will see that it has changed 24 days ago to add polyline clickability. so to solve your problem you need to change your build.gradle from

compile 'com.google.android.gms:play-services:8.3.0'

to

compile 'com.google.android.gms:play-services:8.4.0'

You may fail to add dependencies in your gradle file. Here is a short example: dependencies { compile 'com.google.android.gms:play-services:8.4.0' } But it is just my assumption. Maybe you fail to get google service in your application as well. If you can share more code, I can help you more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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