jawj / OverlappingMarkerSpiderfier

Deals with overlapping markers in Google Maps JS API v3, Google Earth-style
http://blog.mackerron.com
836 stars 238 forks source link

google is not defined #173

Closed massimiliamanto74 closed 2 years ago

massimiliamanto74 commented 2 years ago

Hi all, I have integrated overlapping-marker-spiderfier in my TS project. I load the google api javascript by script in html file and then I load my class where I imports OverlappingMarkerSpiderfier from 'overlapping-marker-spiderfier' but when I use it

const oms = new OverlappingMarkerSpiderfier(this.gmap, this.options);

I receive this error

oms.js:17 Uncaught ReferenceError: google is not defined
    at oms.js:17
    at Object../node_modules/overlapping-marker-spiderfier/lib/oms.js (oms.js:751)
    at __webpack_require__ (bootstrap:19)
    at Module../src/classes/googleMap.ts (utils.js:351)
    at __webpack_require__ (bootstrap:19)
    at Module../src/classes/mapprovider.ts (kakaoMap.ts:431)
    at __webpack_require__ (bootstrap:19)
    at Module../src/classes/onthemap.ts (mapprovider.ts:138)
    at __webpack_require__ (bootstrap:19)
    at onthemap-js-api.min.js:21088

In same block code I check if I need to use MarkerCluster or OverlappingMarkerSpiderfier, both need google map api is loaded. First case (markerCluster) works, second (OverlappingMarkerSpiderfier) don't works.

 if (this._otm?.mcOptions as MarkerClustererOptions) {
....this._cluster = new MarkerClusterer(this._gmap, [], this.mcOptions);
}  else if (this._otm?.olOptions && this._gmap) {
      const oms = new OverlappingMarkerSpiderfier(this._gmap, this.olOptions);
} else {
      this.markers.forEach((marker: google.maps.Marker) => {
        marker.setMap(this._gmap);
      });
    }
massimiliamanto74 commented 2 years ago

Sorry I wrong