var map = null;
var infowindow = new google.maps.InfoWindow();
var bounds = new google.maps.LatLngBounds();
//The list of points to be connected
var markers = [{
"title": 'Duero',
"lat": '40.480243',
"lng": '-3.866172',
"description": '1'
}, {
"title": 'Reyes Catolicos',
"lat": '40.47806',
"lng": '-3.870937',
"description": '2'
}, {
"title": 'Guadarrama',
"lat": '40.478998',
"lng": '-3.878755',
"description": '3'
}];
// var map;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(
parseFloat(markers[0].lat),
parseFloat(markers[0].lng)),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var service = new google.maps.DirectionsService();
var infoWindow = new google.maps.InfoWindow();
map = new google.maps.Map(document.getElementById("map"), mapOptions);
var lat_lng = new Array();
var marker = new google.maps.Marker({
position: map.getCenter(),
map: map,
draggable: true
});
bounds.extend(marker.getPosition());
google.maps.event.addListener(marker, "click", function (evt) {
infowindow.setContent("coord:" + marker.getPosition().toUrlValue(6));
infowindow.open(map, marker);
});
for (var i = 0; i < markers.length; i++) {
if ((i + 1) < markers.length) {
var src = new google.maps.LatLng(parseFloat(markers[i].lat),
parseFloat(markers[i].lng));
createMarker(src);
var des = new google.maps.LatLng(parseFloat(markers[i + 1].lat),
parseFloat(markers[i + 1].lng));
createMarker(des);
// poly.setPath(path);
service.route({
origin: src,
destination: des,
travelMode: google.maps.DirectionsTravelMode.DRIVING
}, function (result, status) {
if (status ==...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.