Christoph M. Becker
4/1/2015 12:43:00 PM
chrisb@ctlsoft.com wrote:
> little script which adds map markers to the appropriate locations with a label.
> The array 'myaddresses' contain the locations to mark on the map and the numbers to put on the labels.
> Works fine for the location bit, but the labels all show the last count (35).
>
> So the line labelContent: myaddresses[x][1] always seems to return the final array element for some reason.
When this expression is evaluated, x === myaddresses.length-1.
> <script type='text/javascript'>
> $(window).load(function(){
> $(document).ready(function () {
That seems clumsy at best. You'll want to skip registering an event
listener for window's load event, here.
> var myOptions = {
> zoom: 6,
> center: new google.maps.LatLng(-42.397, 172.644),
> mapTypeId: 'terrain'
> };
> var map = new google.maps.Map($('#map_canvas')[0], myOptions);
>
> var myaddresses = [['Cambridge', 100], ['Auckland',20], ['Wellington',1], ['Taupo',35]];
>
> for (var x = 0; x < myaddresses.length-1; x++) {
Don't use a for loop here, but rather $.each().
--
Christoph M. Becker