javascript - Google Maps API, problem creating mutliple markers with infowindows via loop -


The problem with the code given below is that the notification window only goes to the last running marker, even when I click on the first marker, opened Infindox on the last marker?

  $ (document) .ready (function () {if (GBrowserIsCompatible ()) {var map = new GMap2 (Document MapEsscontrol (new GSmallMapControl ()); map.setMapType (G_NORMAL_MAP); Map.setCenter (New GLatLng (-29, 24), 5); var cIcon = new GIcon (); cIcon .image = '/img/gmap_marker-01.png'; cIcon.shadow = / img / gmap_marker_shadow-01. Png '; cIcon.shadowSize = new genes (80, 25); cIcon.iconSize = new GSI's (48, 32); CIcon.iconAnchor = new GPoint (23,31); cIcon.infoWindowAnchor = new GPoint (5, 1) ;} Var codes = {96: {axes: -29.11813, lan: 26.2230 9}}, 97: {latitude: - 34.041023, lan: 18.444715}, 98: {latitude: -29.857003, lan: 31.024794}, 99: { Latitude: -33.93264, Lánn: 25.569 9}, 100: {Latitude: -26.201452, lan: 28.045488}, 101: {Latitude: -25.74601 9, Loan: 28.18712}, 142: Late: -33.960396, lan: 22.456244}, {Latitude: -32.99 1009, loan: 27.901569}, 144: {latitude: -31.89701, loan: 26.873444}, 145: {latitude: -28.744031, lawn: 31.889691} , 146: {Latitude: -27.75588, Lan: 29.933845}, 147: {Latitude: -28.737811, Loan: 24.766211}, 148: {Latitude: -26.870491, Lan: 26.664465}, 14 9: {Latitude: -25.668498, Loan : 27.242372}, 150: {Latitude: -25.864549, lawn: 25.642374}, 151: {latitude: -25.4701, lan: 30.97808}, 152: {axis: -23.912257, loan: 29.45355}}; Markerops = {icon: cIcon}; For (branch ID in quotes) {var point = new GLTLNG (Coord [Branch ID] ['Let'], Coord [Royal id] ['Lawn']); Var marker = new GM marker (point, marker option); GEvent.addListener (marker, "click", function () {marker.openInfoWindowHtml ('hello');}); Map.addOverlay (marker); }});  

The reason is that there is no scope of loop, hence the marker's construction will be the latest In your loop, you have to wrap your loop content in the function:

 For  (branch ID in the cord) {function () {var point = new GLatLng (Coord [branch ID] [' Lie]], coors [branchId] ['country']); Var marker = new GM marker (point, marker option); GEvent.addListener (marker, "click", function () {marker.openInfoWindowHtml ('hello');}); Map.addOverlay (marker); } (Branch ID)}  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -