I have an existing map on a page. I can select that element using something along the lines of document.getElementById() to get the HTMLElement javascript object. Is it possible
You can't get google.maps.Map
object from DOM Element
,on which Google Maps object have been constructed. google.maps.Map
is just a wrapper, which controls DOM Element
for viewing the map, and that element does not have reference to its wrapper.
If your problem is only the scope, make map
as a property of window
object, and it will be accessible from everywhere in your page. You can make 'map'
as global by using one of these:
window.map = new google.maps.Map(..)
or
map = new google.maps.Map(...) //AVOID 'var'