GuillaumeLeclerc / vue-google-maps

Google maps component for vue with 2-way data binding
560 stars 653 forks source link

Reading bounds of the map #97

Closed jvv closed 8 years ago

jvv commented 8 years ago

I'm having trouble reading the bounds of the map. I've added bounds to the map element like this: :bounds.sync="map.bounds"

I see the bounds changing in Vue Devtools when I move or zoom the map. But when I try to read the properties of the bounds ( eg: map.bounds.south ) I get undefined.

Bounds in Vue Devtools

screen shot 2016-08-11 at 12 02 28

Bounds in console output of attribute

screen shot 2016-08-11 at 12 03 12

What am I missing? I'd like to load markers from my server based on the bounds the user sees.

smartpierre commented 8 years ago

This is how I retrieve bounds :

this.boundaries.SELat = this.map.bounds.getSouthWest().lat();

this.boundaries.SELng = this.map.bounds.getNorthEast().lng();

this.boundaries.NWLat = this.map.bounds.getNorthEast().lat();

this.boundaries.NWLng = this.map.bounds.getSouthWest().lng();

(I transform Google Maps SW and NE to SE and NW coordinates because that's what I need for ElasticSearch)

jvv commented 8 years ago

Thanks, that did the trick @smartpierre