Google Maps OverlappingMarkerSpiderfier instantiation problems

408 Views Asked by At

I've searhced the site for this error and, while there were several answers, none of them worked for me (or weren't applicable).

I am using google maps API v3 and am trying to implement OverlappingMarkerSpiderfier to solve my problem of overlapping markers. My problem is that I cannot create an instance of an OMS:

    function getStateInfo(){
        //do stuff
        var lat = 42.5724;
        var lon = -74.948052;
        var map = new google.maps.Map(document.getElementById("map"),{draggableCursor:'pointer'});
        var oms = new OverlappingMarkerSpiderfier(map,{markersWontMove: true, markersWontHide: true});
        // do more stuff
        var whiteicon = new GIcon();
        whiteicon.image = "images/whiteCircle.png";
        whiteicon.iconSize = new GSize(11, 11);
        whiteicon.iconAnchor = new GPoint(6, 6);
        whiteicon.infoWindowAnchor = new GPoint(6,6);

        var marker = new GMarker(new GLatLng(lat,lon), {
            draggable: false, 
            title: ($(this).find('COMPANY_NAME').text()), 
            icon: whiteicon,
            map: map
        });
        oms.addMarker(marker);
    }

I get the following error:

InvalidValueError: setMap: not an instance of Map; and not an instance of StreetViewPanorama

I have verified that the error occurs at the time of instantiation and not at marker creation/placement. For thoroughness, here is the code I am trying to use to place markers:

var marker = new GMarker(new GLatLng(lat,long), {
draggable: false, 
title: ($(this).find('COMPANY_NAME').text()), 
icon: whiteicon,
map: map});

...

oms.addMarker(marker);

I have also retrieved a different copy of OMS in the event that there was something wonky with the original (downloaded from github).

If you need to see more code, just let me know what you are looking for. I just posted the lines which are the problem. My map generates properly without OMS - it's just the oms instantiation that is the problem.

1

There are 1 best solutions below

0
On BEST ANSWER

You are using a deprecated Google Maps JavaScript API v2 map with a Google Maps JavaScript API v3 spiderifier.

This is v2 code (GSize, GPoint, GLatLng):

whiteicon.iconSize = new GSize(11, 11);
whiteicon.iconAnchor = new GPoint(6, 6);

var marker = new GMarker(new GLatLng(lat,lon), {