googlemaps / js-markerclusterer

Create and manage clusters for large amounts of markers
https://googlemaps.github.io/js-markerclusterer/
Apache License 2.0
227 stars 84 forks source link

[Markers] Using AdvancedMarkerElement with a `lat` or `lng` of 0 results in it not being drawn. #722

Open GMchris opened 1 year ago

GMchris commented 1 year ago

Steps to reproduce

  1. Create a map, clusterer and an AdvancedMarkerElement
  2. Set the marker's latitude, longitude or both to be 0
  3. Pass marker to clusterer

Code example

const marker = new google.maps.marker.AdvancedMarkerElement({
                    position: { lat: 0, lng: 1 },
                    title: 'Hi',
                });

                markers.push(marker);
            });

            new MarkerClusterer({
                markers,
                map: this.map,
                renderer: new ClusterRenderer(),
            });

Nothing on my map :(

I'm pretty sure this condition from the MarkerUtils is the culprit

        if (marker.position.lat && marker.position.lng) {
          return new google.maps.LatLng(
            marker.position.lat,
            marker.position.lng
          );
        }

and might be fixed by instead doing

        if ('lat' in marker.position && 'lng' in marker.position) {
          return new google.maps.LatLng(
            marker.position.lat,
            marker.position.lng
          );
        }
wangela commented 1 year ago

If you would like to upvote the priority of this issue, please comment below or react on the original post above with :+1: so we can see what is popular when we triage.

@GMchris Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.