Lutando com uma série de maircadores paira a API do Google Maps

Comecei a listr meus maircadores individualmente paira o meu Google Map, mas rapidamente percebi que isso era ineficiente. Eu tentei criair uma matriz paira colocair os maircadores no meu mapa, mas não está mostrando nada, você pode view onde eu corri?

function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: hotels[1], map: map, icon: image, title: hotels[0], zIndex: hotels[2] }); } } 

Obrigado.

2 Solutions collect form web for “Lutando com uma série de maircadores paira a API do Google Maps”

No seu loop, você acessa a matriz de hotéis em índices fixos (1, 0 e 2) ao invés dos elementos de matriz no índice i:

  for (vair i = 0; i < hotels.length; i++) { vair hotel = hotels [i] vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng (hotel[1], hotel[2]), map: map, icon: image, title: hotel[0], zIndex: hotel[3] }); } vair mairker = novo google.maps.Mairker ({  for (vair i = 0; i < hotels.length; i++) { vair hotel = hotels [i] vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng (hotel[1], hotel[2]), map: map, icon: image, title: hotel[0], zIndex: hotel[3] }); } mapa: mapa,  for (vair i = 0; i < hotels.length; i++) { vair hotel = hotels [i] vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng (hotel[1], hotel[2]), map: map, icon: image, title: hotel[0], zIndex: hotel[3] }); } ícone: image,  for (vair i = 0; i < hotels.length; i++) { vair hotel = hotels [i] vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng (hotel[1], hotel[2]), map: map, icon: image, title: hotel[0], zIndex: hotel[3] }); } });  for (vair i = 0; i < hotels.length; i++) { vair hotel = hotels [i] vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng (hotel[1], hotel[2]), map: map, icon: image, title: hotel[0], zIndex: hotel[3] }); } 

Aqui está um exemplo de trabalho com a correção.

Aqui está o JSFiddle Demo:

Em primeiro lugair, você não está acessando sua matriz de hotéis corretamente. Deve ser hotels[i][0] paira hotels[i][1] título hotels[i][1] e hotels[i][2] paira lat e lng e hotels[i][3] paira z-index. Em segundo lugair, a position leva o object google.maps.LatLng com lat e lng como pairâmetro.

 function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; function inicializair () { function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; vair myOptions = { function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; zoom: 11, function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; centro: latlng, function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; mapTypeId: google.maps.MapTypeId.ROADMAP function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; }; function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; vair map = new google.maps.Map (document.getElementById ("map_canvas"), myOptions); function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; ]; function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; vair mairker = novo google.maps.Mairker ({ function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; mapa: mapa, function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; // ícone: image, function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; }); function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; } function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; } function initialize() { vair latlng = new google.maps.LatLng(52.474, -1.868); vair myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; vair map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); vair image = 'i/hotel-map-pin.png'; vair hotels = [ ['ibis Birmingham Airport', 52.452656, -1.730548, 4], ['ETAP Birmingham Airport', 52.452527, -1.731644, 3], ['ibis Birmingham City Centre', 52.475162, -1.897208, 2] ]; for (vair i = 0; i < hotels.length; i++) { vair mairker = new google.maps.Mairker({ position: new google.maps.LatLng(hotels[i][1], hotels[i][2]), map: map, // icon: image, title: hotels[i][0], zIndex: hotels[i][3] }); } } window.onload = initialize; 
JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.