Sean Forman
Sean Forman

Reputation: 400

this.remove is not a function when removing Google Maps Overlay

I have an overlay placed on a google map:

function CustomerMarker(map) {
    this.Map = map;
    this.setMap(map);

}

    GoogleMap = new google.maps.Map(document.getElementById("map"), {
        zoom: 16,
        canZoom: false,
        center: { lat: lat, lng: lng },
        mapTypeControl: false,
        streetViewControl: false,
        scaleControl: false,
        clickableIcons: false
    });

    CustomMarker.prototype = new google.maps.OverlayView();
    CustomMarker.prototype.onAdd = function () {
        //Some code
    };
    CustomMarker.prototype.draw = function () {
        //Some code
    };

    CustomMarker = new CustomMarker(GoogleMap);

Which works fine, and the overlay shows up, however is issue arises when I try to remove that

CustomMarker.setMap(null)

I get an error and the marker remains

Error: this.remove is not a function
pz@https://maps.googleapis.com/maps-api-v3/api/js/30/1/overlay.js:1:251
rk@https://maps.googleapis.com/maps-api-v3/api/js/30/1/overlay.js:2:476
_.pg.prototype.map_changed/<@https://maps.googleapis.com/maps/api
/js?key=AIzaSyBCiIPv6fgrRVn3veTJeP6ihfhrw8AXwbY:125:662
_.G@https://maps.googleapis.com/maps/api/js?key=AIzaSyBCiIPv6fgrRVn3veTJeP6ihfhrw8AXwbY:51:447
_.pg.prototype.map_changed@https://maps.googleapis.com/maps/api/js?key=AIzaSyBCiIPv6fgrRVn3veTJeP6ihfhrw8AXwbY:125:636
Db@https://maps.googleapis.com/maps/api/js?key=AIzaSyBCiIPv6fgrRVn3veTJeP6ihfhrw8AXwbY:37:103
_.k.set@https://maps.googleapis.com/maps/api/js?key=AIzaSyBCiIPv6fgrRVn3veTJeP6ihfhrw8AXwbY:101:728
_.jd/<@https://maps.googleapis.com/maps/api/js?key=AIzaSyBCiIPv6fgrRVn3veTJeP6ihfhrw8AXwbY:55:317

Upvotes: 4

Views: 2553

Answers (2)

Juan Carlos Ortega
Juan Carlos Ortega

Reputation: 1

update your script MarkerClustererPlus

markerclusterer.js @version 2.1.1 [November 4, 2013]

Upvotes: 0

geocodezip
geocodezip

Reputation: 161384

The documentation for OverlayView states:

You must implement three methods: onAdd(), draw(), and onRemove().

I don't see an implementation for onRemove.

Upvotes: 3

Related Questions