I'm new to Javascript in general, and I'm setting up a map and I need to get the bounds of a map I just set up. The thing is I keep getting a message that I'm unable to get getNorthEast() from an undefined value, meaning map.getBounds()
failed to return the map's bounds.
However, the documentation says:
Returns the lat/lng bounds of the current viewport. If more than one copy of the world is visible, the bounds range in longitude from -180 to 180 degrees inclusive. If the map is not yet initialized (i.e. the mapType is still null), or center and zoom have not been set then the result is null or undefined.
The map's center and zoom are defined, so I don't know what could be wrong.
map = new google.maps.Map(document.getElementById('map'), {
center: { lat: -34.397, lng: 150.644 },
zoom: 8
});
var bounds = map.getBounds();
var origNE = bounds.getNorthEast();
var origSW = bounds.getSouthWest();