设置Google地图类型时:
map.setMapTypeId(google.maps.MapTypeId.TERRAIN);
我可以用包含字符串“TERRAIN”,“SATELLITE”等的js变量替换“TERRAIN”吗?
答案 0 :(得分:9)
是的,请这样称呼:
var mapType = "TERRAIN";
map.setMapTypeId(google.maps.MapTypeId[mapType]);
答案 1 :(得分:-1)
//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