Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API v3 MapTypeId as variable

When setting the google map type:

map.setMapTypeId(google.maps.MapTypeId.TERRAIN);

Can I replace "TERRAIN" by a js variable containing the string "TERRAIN", "SATELLITE", etc?

like image 789
MrUpsidown Avatar asked Feb 22 '26 12:02

MrUpsidown


1 Answers

Yes, call it like this:

var mapType = "TERRAIN";
map.setMapTypeId(google.maps.MapTypeId[mapType]);
like image 190
Mathletics Avatar answered Feb 25 '26 01:02

Mathletics



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!