javascript - Google Maps API v3 MapTypeId as variable - Stack Overflow

When setting the google map type:map.setMapTypeId(google.maps.MapTypeId.TERRAIN);Can I replace "TE

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?

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?

Share Improve this question asked Aug 2, 2012 at 0:15 MrUpsidownMrUpsidown 22.5k15 gold badges83 silver badges141 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

Yes, call it like this:

var mapType = "TERRAIN";
map.setMapTypeId(google.maps.MapTypeId[mapType]);
//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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744742520a4591111.html

相关推荐

  • javascript - Google Maps API v3 MapTypeId as variable - Stack Overflow

    When setting the google map type:map.setMapTypeId(google.maps.MapTypeId.TERRAIN);Can I replace "TE

    3天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信