Skip to main content
Participating Frequently
May 29, 2009
Answered

incrementing variable names - how do I do it? Google Maps API

  • May 29, 2009
  • 2 replies
  • 762 views

I am trying to integrate google maps into my website. I want the user to be able to view my company's current customers on the map.

I can query my database and get the customer's Name, and longitude, latitude.

I can make a single marker on the map like this:

var marker = new GMarker(new GLatLng(<cfoutput>#geoip.testilat#</cfoutput>, <cfoutput>#geoip.testilong#</cfoutput>));
      GEvent.addListener(marker, "click", function() {
          var html = '<div style="width: 210px; padding-right: 10px"><cfoutput>#geoip.schoolName#</cfoutput><br><cfoutput>#geoip.text#                          </cfoutput><\/div>';
        marker.openInfoWindowHtml(html);
       
      });

map.addOverlay(marker);
     
GEvent.trigger(marker, "click");

But I need to iterate through the database and create a marker for each row, with a different variable name for each, ie. marker, marker1, etc..

I know I need to build some sort of loop but I don't know how. Can someone point me in the right direction?

Thanks

    This topic has been closed for replies.
    Correct answer ilssac

    currentRow is created by the <cfoutput query=""> looping over a recordset object created by a <cfquery...>

    I presume from your code example that geoip was a record set from a query.  If not, you can use any variable for this that is handy to your logic.

    2 replies

    ilssac
    Inspiring
    May 29, 2009

    Well no, you are not creating different variable names, not to ColdFusion.  In ColdFusion you are outputing text.  That the text happens to be JavaScript that will be run on the client which will create JS variables is of no concern to ColdFusion.  Just loop over the output and build the JS function just the same as if you where building an HTML table or some other iterative display.

    <cfoutput query="geoip">

    var marker#geoip.currentRow# = new GMarker(new
    GLatLng(#geoip.testilat#,
    #geoip.testilong#));

          GEvent.addListener(marker#geoip.currentRow#, "click", function() {
            
    var html = '<div style="width: 210px; padding-right:
    10px">#geoip.schoolName#><br>#geoip.text#       
                      <\/div>';

            marker#geoip.currentRow#.openInfoWindowHtml(html);
           
          });

    </cfoutput>

    Participating Frequently
    May 29, 2009

    That makes sense. But how do I define currentRow?

    Sorry, I'm new to all this.

    ilssac
    ilssacCorrect answer
    Inspiring
    May 29, 2009

    currentRow is created by the <cfoutput query=""> looping over a recordset object created by a <cfquery...>

    I presume from your code example that geoip was a record set from a query.  If not, you can use any variable for this that is handy to your logic.

    Participating Frequently
    May 29, 2009

    oh, and here is the exmple website: http://betaweb.computerlabsolutions.com/success/geolocate.cfm

    and query dump: http://betaweb.computerlabsolutions.com/marktest.cfm