Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get google.maps.Map instance from a HTMLElement

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 to get the instance of google.maps.Map created when the map is initialised, i.e. is it a property of the HTMLElement object or in its prototype?

like image 467
Olly Hicks Avatar asked Apr 20 '12 20:04

Olly Hicks


People also ask

How do I extract a Google map?

To download your data, head to Google Maps on your computer and sign in. Next, click the three-line menu icon in the top-left corner next to the Search box. Near the bottom, select “Your Data in Maps.” On the next screen, scroll down to and select “Download Your Maps Data.”

Is Google Maps API free?

The API is available for developers that have a free Google Maps API key. Usage of the API is not strictly free, but they do offer $200 of free monthly usage for most users. The pricing scales to fit your particular needs and you are only charged for your API usage.

How do I link Google Maps to HTML?

Click Share or embed map. Click Embed map. Copy the text in the box. Paste it into the HTML of your website or blog.


1 Answers

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'  
like image 74
Engineer Avatar answered Sep 23 '22 14:09

Engineer