Skip to content

Instantly share code, notes, and snippets.

@hugodias
Created October 26, 2012 12:08
Show Gist options
  • Save hugodias/3958416 to your computer and use it in GitHub Desktop.
Save hugodias/3958416 to your computer and use it in GitHub Desktop.
Google maps como chegar
var maps;
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var infoWindow = new google.maps.InfoWindow({maxWidth: 460});
var markerOffice = new google.maps.Marker({
title: 'MARK_TITLE_HERE',
//icon: 'site/images/icon-feed.gif', // icon
position: new google.maps.LatLng('LAT_HERE', 'LONG_HERE')
});
function initialize() {
var options = {
zoom: 15,
center: markerOffice.position,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("mapa"), options);
markerOffice.setMap(map);
google.maps.event.addListener(markerOffice, 'click', function() {
infoWindow.setContent('HTML_MARK_CONTENT');
infoWindow.open(map, markerOffice);
});
}
$(function() {
$('#form-endereco-rota').submit(function() {
infoWindow.close();
markerOffice.setMap(null);
directionsDisplay.setMap(null);
directionsDisplay = new google.maps.DirectionsRenderer();
var request = {
origin: $("#endereco").val(),
destination: markerOffice.position,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
directionsDisplay.setMap(map);
}
});
return false;
});
initialize();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment