Q:

Toggling GeolocationMarker() in Google Maps, once setMap(null) is completed it won't turn back on

I'm trying to figure out why GeolocationMarker() responds differently than a normal marker.
With a simple marker you can toggle it on and off using marker.setMap(map) and marker.setMap(null). But when I do this with a GeoMarker, once I turn it off I can't get it to turn back on consistently.
controlUI.addEventListener('click', function() {
    if (content == 'zoomIn') {
        map.setZoom(map.getZoom() + 1);
    } else if (content == 'zoomOut') {
        map.setZoom(map.getZoom() - 1);
    } else if (content == 'myGeolocation') {
        //If there is no GeolocationMarker, this makes one and turns it on.
        if (watchRunning == 0) {
            GeoMarker = new GeolocationMarker({
                enableHighAccuracy: false
            });
            GeoMarker.setMap(map);
            watchRunning = 1;
            document.getElementById(content).style.backgroundColor =
                'rgba(30, 144, 255,.8)';
            document.getElementById("imgGeolocation").src =
                "geolocation_white.png";
            //If the GeolocationMarker is on, this turns it off.
        } else if (watchRunning == 1) {
            GeoMarker.setMap(null);
            document.getElementById(content).style.backgroundColor =
                'rgba(255,255,255,.7)';
            document.getElementById("imgGeolocation").src =
                "geolocation_black.png";
            watchRunning = 2;
            //If the GeolocationMarker is off, this should turn it back on.
        } else {
            GeoMarker.setMap(map);
            document.getElementById(content).style.backgroundColor =
                'rgba(30, 144, 255,.8)';
            document.getElementById("imgGeolocation").src =
                "geolocation_white.png";
            watchRunning = 1;
        };
    }
})

This should show it on the map...
GeoMarker.setMap(map);

And this should hide it...
GeoMarker.setMap(null);

All of these things work correctly, at first.  The problem is when the user toggles the on/off a few times. The GeoMarker will not consistently turn back on. I can usually get it to work once or twice, after that it will not turn back on.
Any thoughts on why this may be happening? I understand that placing it in the Event Listener isn't the ideal place for the actual function, but the rest of it works as far as the background and img changing.

A:

assuming the variables are defined correctly(otherwise it wouldn't work at all) and you use this library: https://google-maps-utility-library-v3.googlecode.com/svn/trunk/geolocationmarker/docs/reference.html
As it seems each time when you show the marker the library will re-run the geolocation-part(what may take some time and may have undesired side-effects  ).
Possible workaround: don't toggle the map-property, toggle the visibility instead:
     if (watchRunning == 0) { 
        GeoMarker = new GeolocationMarker({
            enableHighAccuracy: false
        });
        GeoMarker.setMap(map);

        watchRunning = 1;
        document.getElementById(content).style.backgroundColor =
            'rgba(30, 144, 255,.8)';
        document.getElementById("imgGeolocation").src =
            "geolocation_white.png";
        //If the GeolocationMarker is on, this turns it off.
    } else if (watchRunning == 1) {
        GeoMarker.setMarkerOptions({visible:false});
        GeoMarker.setCircleOptions({visible:false});
        document.getElementById(content).style.backgroundColor =
            'rgba(255,255,255,.7)';
        document.getElementById("imgGeolocation").src =
            "geolocation_black.png";
        watchRunning = 2;
        //If the GeolocationMarker is off, this should turn it back on.
    } else {
        GeoMarker.setMarkerOptions({visible:true});
        GeoMarker.setCircleOptions({visible:true});
        document.getElementById(content).style.backgroundColor =
            'rgba(30, 144, 255,.8)';
        document.getElementById("imgGeolocation").src =
            "geolocation_white.png";
        watchRunning = 1;
    };

