MrUpsidown
MrUpsidown

Reputation: 22486

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?

Upvotes: 3

Views: 2643

Answers (2)

DarckBlezzer
DarckBlezzer

Reputation: 4764

//Console output of MapTypeId
google.maps.MapTypeId
{ROADMAP: "roadmap", SATELLITE: "satellite", HYBRID: "hybrid", TERRAIN:"terrain"}
HYBRID:"hybrid"
ROADMAP:"roadmap"
SATELLITE:"satellite"
TERRAIN:"terrain"


//change mapTypeId
map.setMapTypeId("terrain"); //example with hybrid
//or
map.setMapTypeId(google.maps.MapTypeId.TERRAIN); // same example with hybrid
//or as you want
map.setMapTypeId(google.maps.MapTypeId["TERRAIN"]); // same example with hybrid

Upvotes: -1

Evan Davis
Evan Davis

Reputation: 36592

Yes, call it like this:

var mapType = "TERRAIN";
map.setMapTypeId(google.maps.MapTypeId[mapType]);

Upvotes: 9

Related Questions