Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Google Maps v3 mapOptions object after load

Tags:

How can i modify a V3 map's mapOptions (after the initial map has been loaded)?

Specifically, I would like to be able to flip the

draggable: false 

option to

draggable: true 

When an action (such as a click on a div) is triggered.

Addition: I have tried loading jquery-ui-map and using:

$('#map').gmap('option', 'draggable', true); 

However this seems to reload the map and forget all the other existing options. I could redefine them all, but that seems a bit hackish.

Any pointers appreciated.

Thanks!

like image 620
user1051849 Avatar asked Aug 22 '12 11:08

user1051849


People also ask

Can you customize Google Maps API?

The Google Maps APIs now support you in creating beautiful styled maps for your Android and iOS apps as well as your website using the same JSON style object.


1 Answers

Found that I don't even need jQuery for this – it's already part of the Google Maps API. Simply do:

map.set('draggable', true); 

Too easy! Hope it helps someone.

====== 2020 update - you should use:

map.setOptions({ draggable: true }); 
like image 156
user1051849 Avatar answered Sep 28 '22 08:09

user1051849