admin管理员组

文章数量:1333632

I've recently switched from com.google.android.gms:play-services-maps:18.0.2 to com.google.android.gms:play-services-maps:19.0.0 but I'm getting crashes in my app while adding polygons to the googleMap.

With older version it is working fine, but new one throws ClassCastException

java.lang.ClassCastException: com.squareup.moshi.LinkedHashTreeMap cannot be cast to android.os.Parcelable 
                                                                                                        at com.google.android.gmsmon.internal.safeparcel.SafeParcelWriter.writeTypedList(com.google.android.gms:play-services-basement@@18.3.0:5)
                                                                                                        at com.google.android.gms.maps.model.PolygonOptions.writeToParcel(com.google.android.gms:play-services-maps@@19.0.0:2)
                                                                                                        at com.google.android.gms.internal.maps.zzc.zze(com.google.android.gms:play-services-maps@@19.0.0:3)
                                                                                                        at com.google.android.gms.maps.internal.zzg.addPolygon(com.google.android.gms:play-services-maps@@19.0.0:2)
                                                                                                        at com.google.android.gms.maps.GoogleMap.addPolygon(com.google.android.gms:play-services-maps@@19.0.0:2)

Is there any major change that has occured in PolygonOptions? Because I can't find anything there. PolygonOptions.writeTypedList is used only for points and stroke pattern. This is function I'm using to add polygons:

private fun addPolygon(polygonData: Pair<*, PolygonOptions>) {
    googleMap?.addPolygon(polygonData.second)?.let {
        it.tag = polygonData.first
        polygons.add(it)
    }
}

Inside points there is just List<LatLng> with values. But

19.0.0:

[{latitude=32.4016388, longitude=22.6369665}, {latitude=32.2016388, longitude=22.6369665}]

18.0.2:

[lat/lng: (32.4016388,22.6369665), lat/lng: (32.2016388,22.6369665)]

This is main difference I see. Its both for holes list and points list

I've tried to manually create PolygonOptionsAdapter utilizing @FromJson and @ToJson but it is returning some obfuscated names for variables.

Instead of points there is field called zza, then you have zzb, zzc.

I don't think I can manually create adapter to deserialize and serialize this json from com.google.android.gms.maps.model since its decompiled as class file.

I've recently switched from com.google.android.gms:play-services-maps:18.0.2 to com.google.android.gms:play-services-maps:19.0.0 but I'm getting crashes in my app while adding polygons to the googleMap.

With older version it is working fine, but new one throws ClassCastException

java.lang.ClassCastException: com.squareup.moshi.LinkedHashTreeMap cannot be cast to android.os.Parcelable 
                                                                                                        at com.google.android.gmsmon.internal.safeparcel.SafeParcelWriter.writeTypedList(com.google.android.gms:play-services-basement@@18.3.0:5)
                                                                                                        at com.google.android.gms.maps.model.PolygonOptions.writeToParcel(com.google.android.gms:play-services-maps@@19.0.0:2)
                                                                                                        at com.google.android.gms.internal.maps.zzc.zze(com.google.android.gms:play-services-maps@@19.0.0:3)
                                                                                                        at com.google.android.gms.maps.internal.zzg.addPolygon(com.google.android.gms:play-services-maps@@19.0.0:2)
                                                                                                        at com.google.android.gms.maps.GoogleMap.addPolygon(com.google.android.gms:play-services-maps@@19.0.0:2)

Is there any major change that has occured in PolygonOptions? Because I can't find anything there. PolygonOptions.writeTypedList is used only for points and stroke pattern. This is function I'm using to add polygons:

private fun addPolygon(polygonData: Pair<*, PolygonOptions>) {
    googleMap?.addPolygon(polygonData.second)?.let {
        it.tag = polygonData.first
        polygons.add(it)
    }
}

Inside points there is just List<LatLng> with values. But

19.0.0:

[{latitude=32.4016388, longitude=22.6369665}, {latitude=32.2016388, longitude=22.6369665}]

18.0.2:

[lat/lng: (32.4016388,22.6369665), lat/lng: (32.2016388,22.6369665)]

This is main difference I see. Its both for holes list and points list

I've tried to manually create PolygonOptionsAdapter utilizing @FromJson and @ToJson but it is returning some obfuscated names for variables.

Instead of points there is field called zza, then you have zzb, zzc.

I don't think I can manually create adapter to deserialize and serialize this json from com.google.android.gms.maps.model since its decompiled as class file.

Share Improve this question edited Nov 20, 2024 at 16:48 Martin asked Nov 20, 2024 at 12:22 MartinMartin 2,9149 gold badges53 silver badges99 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

I'd suspect, the model class being used for Moshi's ORM is not being properly annotated, because else it should indeed be List<LatLng> or ArrayList<LatLng>... the other option would be making it parcel-able, which is probably not required, when returning the expected data-type with ORM. That * in the signature should be ArrayList<LatLng> ...because with * this fails one call later, when passing an unexpected argument.

本文标签: androidGoogleMapServices Adding Polygon to the map causes exception in version 1900Stack Overflow