admin管理员组文章数量:1391937
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 badges2 Answers
Reset to default 9Yes, 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
本文标签: javascriptGoogle Maps API v3 MapTypeId as variableStack Overflow
版权声明:本文标题:javascript - Google Maps API v3 MapTypeId as variable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744742519a2622692.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论