Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google maps (V3) - Map container selector (using jquery)

I'm trying to solve a tricky problem in Google Maps (api V3)

Works nicely:

var map = new google.maps.Map(document.getElementById("map_container"), myOptions);

Doesn't Work if I try to use a jQuery selector

var map = new google.maps.Map($('#map_container'), myOptions);

I made this EXAMPLE


Thank you in advance

Cheers

Pedro

like image 333
Pedro Gil Avatar asked Oct 01 '10 12:10

Pedro Gil


1 Answers

It expects a DOM element, but $('#map_container') returns a jQuery object. If you want to use a jQuery selector, do:

var map = new google.maps.Map($('#map_container')[0], myOptions);

Or you can also use .get(0) instead of [0], this returns the actual DOM object.

like image 61
reko_t Avatar answered Oct 07 '22 19:10

reko_t