googlemaps-samples / android-samples

Samples demonstrating how to use Maps SDK for Android
https://developers.google.com/maps/documentation/android-sdk/
Apache License 2.0
2.42k stars 2.99k forks source link

[Google Maps SDK for Android] Polygon fill color disappeared at some zoom levels #693

Closed meor9zcu12 closed 3 years ago

meor9zcu12 commented 3 years ago
  1. API Google Maps SDK for Android

  2. OS type and version Android 11, Android 7

  3. Library version and other environment information

    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.2'
        classpath 'com.google.gms:google-services:4.3.10'
    }
    
    android {
    compileSdk 30
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    }

dependencies { implementation 'com.google.android.gms:play-services-maps:17.0.1' implementation 'com.google.maps.android:android-maps-utils:2.2.5' }


#### Steps to reproduce

  1.  Copy the code below and then run
  2.  Zoom in or zoom out on the Google Map

#### Code example (Edited)

public class MyMapFragment extends com.google.android.gms.maps.SupportMapFragment implements OnMapReadyCallback, GoogleMap.OnMapLoadedCallback { private GoogleMap googleMap;

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getMapAsync(this);
}

@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
    this.googleMap = googleMap;
    googleMap.setOnMapLoadedCallback(this);
}

@Override
public void onMapLoaded() {
    LatLngBounds.Builder builder = new LatLngBounds.Builder();

    String encodedPath = "{k|sFvmgcMf@_DwG_Dg@wBnAwBvGg@nKrIvG_D~CbBoAbLoAbBwBkCwBbBf@jC~CbB~RkCfE{EnK{@vGnA~HsNvBz@vB~MfESnFwQfERvG~H~CRvBoFfOwB~Cf@oAbBnFfEvBcB_DsXf@_D~CnKjHRbB{ES_SjHkCjCgJvG_IzE?bLsIfEkHf@oKzEg@rIoPvGgY{@kHbBk\\~R{@jWcGr{@we@j\\{c@nA~HzJ{JwB?kCfEcBoAz@_IzJkHRnKzEfERvGwBnAsDoFcBz@_DvGfEoFvBnAcLfT~McQkHz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@fJ~HR~H~H~\\zJfEnKgE~Cwe@kC?rDgE~HwBwGoPwBgEnAoFrNgTbLgJ{J_DkHf@cLwB_N~HgToAsIoAoFwGgE_DoK_D_DsXsNkW{@on@oPwj@cVwaBsDogAS_k\\cBoiTfwJ_xNfdGwcFfxBgfFrmBwfGbxCw~@gvCghEglH_{@s~A_xDgdGogA{iBnKsbJvGctO~MwVfYoKnPSvLzEnPf@vLcGnPz@bBgJ{@{@bB{@SkCnKgY~HsDvG_IbGSnUkHb[gOfEcGnKwBvGcGnd@RjHnFrXbGjMgEnUw[rDkWjH{ObBoUbBsXsDoU?kk@kCcVsIk\\jC{|@{@_IvBwBz@wGz@crArNc`@~Hkk@kCoZvB{JvGkHjMgEnAcB{@cB~WcV?cQolFgdGnF{EvBoKfJgEnP{@fEwLvLkM";

    List<LatLng> latLngs = PolyUtil.decode(encodedPath);

    PolygonOptions polygonOptions = new PolygonOptions();
    polygonOptions.strokeWidth(5);
    polygonOptions.fillColor(Color.CYAN);

    for (LatLng latLng : latLngs) {
        builder.include(latLng);
    }
    polygonOptions.addAll(latLngs);

    googleMap.addPolygon(polygonOptions);

    googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 50));
}

}



#### Preview (Edited)
![map](https://user-images.githubusercontent.com/82598626/132155852-ef6e3c17-8580-45ff-81d5-394a9f9e0024.gif)

#### Expected result
The fill color of the polygon should be shown no matter what zoom level is.

#### Actual result
Fill color works for some simple polygons, but for some complicated polygon like this, the fill color does not work at some zoom levels.

#### Stack trace
None
barbeau commented 3 years ago

This sounds a lot like these issues:

If the polygon isn't closed correctly, or is complex, the Android Maps SDK has issues rendering the fill correctly. I'd encourage you to check and make sure the polygon is correct, and then star and follow the top issue above.

meor9zcu12 commented 3 years ago

I used https://developers.google.com/maps/documentation/utilities/polylineutility to decode my polyline, image

The start point and the end point listed, are the same (40.12750,-74.09900) Level: 3, therefore the polygon should be closed.

Anyway, I maybe better to share my case to issue tracker.

Thank you.