Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从嵌套数组添加google地图标记_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 从嵌套数组添加google地图标记

Javascript 从嵌套数组添加google地图标记,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我已使用以下代码成功地将标记添加到地图: var film = [ [ "12 Years a Slave",-90.0715323,29.9510658,"2013"], [ "12 Years a Slave",-90.7197143,30.0110809,"2013"]]; for (i = 0; i < film.length; i++) { marker = new google.maps.Marker({ position: new google.maps.Lat

我已使用以下代码成功地将标记添加到地图:

var film = [
[ "12 Years a Slave",-90.0715323,29.9510658,"2013"],
[ "12 Years a Slave",-90.7197143,30.0110809,"2013"]];

for (i = 0; i < film.length; i++) {  
  marker = new google.maps.Marker({
  position: new google.maps.LatLng(film[i][2], film[i][1]),
});

如何一次打开所有的标记,或者只打开一部电影?在这个循环中是否需要第二种类型的for循环?

是的,您需要第二种for循环来遍历每个胶片的位置(因为现在一个胶片有多个位置)

根据以上代码,这应该可以实现以下功能:

//浏览每一部电影
对于(i=0;i

要显示单个胶片,请使用
displayFilm
功能。要显示所有内容,请使用第一个for循环调用每部影片的函数。

抱歉,我还没有访问我的笔记本电脑进行尝试-今晚将进行测试并让您知道-非常感谢您的回答。很高兴听到这一点;)
var film = [["12 Years a Slave","2013",[[-90.3517469,29.9429828],[-90.1525373,29.9502543]]],
["The Life of Emile Zola","1937",[[-117.7603323,33.5141933],[-118.3387185,34.1486546]]]];