3

Hello I have a Javascript code that shows a map with pins using there locations as adresses. The adresses are read from an array and the array structure is like that :

var locations = ["1915 Edgewater Drive,Orlando,FL", "5555 Kirkman Rd.,Orlando,FL", "4965 Oak Ridge Road,Orlando,FL", "3011 E Colonial Dr,Orlando,FL", "300 Park Avenue,Winter Park,FL"];

The code used to show the map with the pins is as following :

function initialize() {
  //Planned direction display
  directionsDisplay = new google.maps.DirectionsRenderer({
      polylineOptions : {
          strokeColor : 'brown',
          strokeOpacity : 0.7,
          strokeWeight : 3
      },
      suppressMarkers : true,
      suppressPolylines : true
  });

  //actual direction display
  directionsDisplayActual = new google.maps.DirectionsRenderer({
      polylineOptions : {
          strokeColor : 'brown',
          strokeOpacity : 0.7,
          strokeWeight : 3
      },
      suppressMarkers : true,
      suppressPolylines : true
  });

    geocoder = new google.maps.Geocoder();
    geocoder.geocode( { 'address': locations[0] }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {

        var chicago = new google.maps.LatLng(results[0].geometry.location.ob, results[0].geometry.location.pb);
          var mapOptions = {
                zoom: 6,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                center: chicago
          }
          map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
          map_actual = new google.maps.Map(document.getElementById('map-actual'), mapOptions);
          calcRoute();
        }
    });

}

Now instead of using locations with adresses I have a series of longitude and latitude coordinates like that :

var coordinates = [[28.378929,-80.6006008],[28.378628084853,-80.600730804958],[28.378956475407,-80.600553605881],[28.378929693408,-80.60055175679],[28.378785540514,-80.60065325285],[28.378935283517,-80.600646565422],[28.378950753943,-80.600504807166]]

So How can I change my code to use those coordinates instead of locations adresses?

Thanks.

OussamaLord
  • 1,073
  • 5
  • 28
  • 39

1 Answers1

2

Try this:

var coordinates = [[28.378929,-80.6006008],[28.378628084853,-80.600730804958],[28.378956475407,-80.600553605881],[28.378929693408,-80.60055175679],[28.378785540514,-80.60065325285],[28.378935283517,-80.600646565422],[28.378950753943,-80.600504807166]];
// loop through your array of coordinates
for(var i = 0; i < coordinates.length; i++){
    // create a new marker and add it to the map
    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(coordinates[i][0], coordinates[i][1]),
        map: map
    });
}

Edit: You use the LatLng object instead of geocoding your addresses

pascal
  • 641
  • 4
  • 12