0

Is there a way to get the bounding rectangle (screen position) of Google Map API markers? I am using an Angular 2 wrapper, so I don't construct the markers like you would normally with the API (mostly irrelevant here though).

Or are they on an internal canvas with no way to pull position like you would with an html element?

I have tried something like this, but getBoundingRectangle() comes back with zero values:

      var googleMapContent = document.getElementsByClassName("sebm-google-map-content")[0];

      var markerList = googleMapContent.getElementsByTagName("sebm-google-map-marker");

      if( markerList.length > 0 ) {
          for (var i = 0; i < markerList.length; i++ ){
             var marker = markerList[i];
             var markerLabel = marker.getAttribute("ng-reflect-label");
             var boundingRectangle = marker.getBoundingClientRect();
          }
      }

P.S. I have access to map center lat/lng + zoom and marker lat/lng, so I can "math" this, but that's pretty dirty.

VSO
  • 11,546
  • 25
  • 99
  • 187

1 Answers1

1

The Marker class hasn't got either a getBoundingRectangle or getBoundingClientRect method.

It has got getPosition() and getShape() though, which in combination might give you the information you need.

duncan
  • 31,401
  • 13
  • 78
  • 99
  • The native marker class does - I don't have access directly to markers because of the Angular 2 API, I can only pull them from the dom. But ty, `getShape()` is promising. – VSO Mar 16 '17 at 17:38