I'm trying to make Google Maps automatically set driving routes for destinations that are stored in my database. Basically, I have a few addresses in my databases(i.e: manufacturers) and I want to be able to enter a zip code(or an address) to receive the directions from that zipcode/address to all the manufacturers available(and maybe for a fancy extra, fetch the closest manufacturer). I've never used Google Maps API before so I'm fairly confused by it. So far, I've only been able to set markers to the available manufacturers. As for the driving routes, I've looked for hours and it's a bit complex to digest. What way would you suggest me to take(no pun intended) with this piece of code that I have so far?
echo "<script>
var locations =
[
";
for($i = 0; $i < sizeof($locations); $i++)
{
echo "['".$locations[$i][0]."', '".$locations[$i][1]."', ".$locations[$i][2].", ".$locations[$i][3].", ". ($i+1) ." ]";
if (! ($i == (sizeof($locations)-1)) )
echo ",";
}
echo "];
var map = new google.maps.Map(document.getElementById('map'),
{
zoom: 15,
center: new google.maps.LatLng(45.892235, -72.5371626),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++)
{
marker = new google.maps.Marker(
{
position: new google.maps.LatLng(locations[i][2], locations[i][3]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i)
{
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>";