JavaScript Google Maps - Creating multiple markers google maps creating a route,google maps creating a map,

I'm having a bit of trouble trying to loop out multiple markers onto a map using information stored in an array.

The code creates the map no problem, but it's not displaying the markers I'm trying to loop out...

As you can see from the code below, there are two functions that are creating markers. The first is simply using two values. This marker displays fine.

The second function however, is grabbing the data from an array (the array has been set up to "squish" the latitude and longitude data together, in that order, as Google Maps requires it to be) and does not display anything when run.

Any ideas? I'm stumped!

Thanks in advance!

Here's the code:

Initial "locations" array:

var locations = new Array();

for (var i = 0; i < data.length; i++)
        {
        var row = data[i];   

        var longitude = row[0];
        var latitude = row[1];

        locations[i] = latitude + longitude;
        }

callMap(locations, locationFilename, userLatitude, userLongitude);

Google Maps Functions

    function callMap(locations, locationFilename, userLatitude, userLongitude) {

 var mapOptions = {
      zoom:16,
      center: new google.maps.LatLng(userLatitude, userLongitude),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var map = new google.maps.Map(document.getElementById('mapView'),mapOptions);

    setMarkers(map, locations, locationFilename);
    currentPosition(map, userLatitude, userLongitude);
  }

  function currentPosition(map, userLatitude, userLongitude)
  {

  var userLatLng = new google.maps.LatLng(userLatitude, userLongitude);

    var marker = new google.maps.Marker({
        position: userLatLng,
        map: map
            });

  }

  function setMarkers(map, locations, locationFilename) {

    for (var i = 0; i < locations.length; i++) {

    var markerLatLng = new google.maps.LatLng(locations[i]);

            var marker = new google.maps.Marker({
                position: markerLatLng,
                map: map
                    });

    }
  }
Answer:1

A google.maps.LatLng takes two numbers for arguments.

This is not correct:

var markerLatLng = new google.maps.LatLng(locations[i]);

This should work:

for (var i = 0; i < data.length; i++)
    {
    var row = data[i];   

    var longitude = row[0];
    var latitude = row[1];

    locations[i] = new google.maps.LatLng(latitude,longitude);
    }

Then

function setMarkers(map, locations, locationFilename) {

  for (var i = 0; i < locations.length; i++) {

    var markerLatLng = locations[i];

        var marker = new google.maps.Marker({
            position: markerLatLng,
            map: map
        });

    }
  }
}
Answer:2

I'm trying to find a way to get a url from an iframe and using javascript modify the link and move to a another page. basicly the address in the iframe is something like "http://www.somthing.com/12/...

I'm trying to find a way to get a url from an iframe and using javascript modify the link and move to a another page. basicly the address in the iframe is something like "http://www.somthing.com/12/...

Here's a replication of the problem: I get the timestamp of now via JavaScript as var ts = +new Date // 1368971991090 console.log( new Date(1368971991090) ); // Sun May 19 2013 13:59:51 GMT+0000 (GMT)...

Here's a replication of the problem: I get the timestamp of now via JavaScript as var ts = +new Date // 1368971991090 console.log( new Date(1368971991090) ); // Sun May 19 2013 13:59:51 GMT+0000 (GMT)...

I am using the following coding for the script in external file function DiableLink(elem){ console.log($(elem).attr('type')); if($(elem).hasClass('disabled')) { return false; } ...

I am using the following coding for the script in external file function DiableLink(elem){ console.log($(elem).attr('type')); if($(elem).hasClass('disabled')) { return false; } ...

I am receiving the following message when I try to use Backbone's collection.each() method: TypeError: Object function (){ return parent.apply(this, arguments); } has no method 'each'. I'm learning ...

I am receiving the following message when I try to use Backbone's collection.each() method: TypeError: Object function (){ return parent.apply(this, arguments); } has no method 'each'. I'm learning ...

  1. backbone collection each example
  2. backbone collection each
  3. backbone collection each break
  4. backbone js collection each
  5. backbone collection foreach
  6. backbone this.collection.each is not a function