I am trying to find a better way to center my google map.
I've already written code to add in Markers to Outline and area squarely of which is being store in an array: Coords[i], in-which when returning to the map after save, it centers the map window based on the "first marker" lat/lng coordinates Coords[0].
I am trying to figure out a better way to center the map where there is adequate space around my outline area.
I've try doing it on Dragend, which works somewhat:
google.maps.event.addListener(this.map, 'dragend', function(mapEvent) {
var lat = mapEvent.getCenter() .lat(),
lng = mapEvent.getCenter() .lng(),
console.log(lat + " " + lng + " " + this);
});
But it keeps throwing an error saying: "Unable to get property 'getCenter' of undefined or null reference"
Can someone tell me what I am doing wrong OR tell be a better way to achieve what I'm trying to do?
As, another option
It would be nice if possible if I can keep the first marker [0] the centering marker as it is already, But don't allow it to outline... just the markers 1 + and on .... But I don't know how to modify my code to do that.
Just looking for a solution that works.
My complete Code is here: http://pastiebin.com/embed/593d6d809e2f0