Google map api v3にて1ページに地図を複数回表示する処理をjavascriptで実装したいのですが、うまく行きません。。
javascript
1var geocoder; 2var map; 3 4$(function() { 5 geocoder = new google.maps.Geocoder(); 6 testFunction(); 7}); 8 9function testFunction() { 10 11 var options = { 12 zoom: 18 13 ,mapTypeId: google.maps.MapTypeId.ROADMAP 14 }; 15 16 var map; 17 18 for (var i = 1; i <= 2; i++) { 19 20 var map = new google.maps.Map(document.getElementById('map_canvas_' + i), options); 21 22 geocoder.geocode({'address': $('#address_' + i).val()}, function(results, status) { 23 24 if (status == google.maps.GeocoderStatus.OK) { 25 map.setCenter(results[0].geometry.location); 26 var marker = new google.maps.Marker({ 27 map: map 28 ,position: results[0].geometry.location 29 }); 30 } else { 31 alert("Geocode was not successful for the following reason: " + status); 32 } 33 }); 34 35 map = new google.maps.Map(document.getElementById('map_canvas_' + i), options); 36 37 } 38}
上記のコードだと、2番目の地図が表示され、一番目の地図は表示されません。
このAPIの仕様について詳しい方ご教授お願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/08/15 07:32