Skip to content

Instantly share code, notes, and snippets.

@anneallen
Created May 13, 2014 21:16
Show Gist options
  • Save anneallen/ddd383b1bba13d0348af to your computer and use it in GitHub Desktop.
Save anneallen/ddd383b1bba13d0348af to your computer and use it in GitHub Desktop.
Google maps API v3 Directions using data from cmb_field_map_master
//Using safe jquery for Wordpress
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var myLatlng = new google.maps.LatLng(jQuery( '#stores li' ).data( 'latitude' ), jQuery( '#stores li' ).data( 'longitude' ));
var mapOptions = {
zoom:10,
center: myLatlng
}
map = new google.maps.Map(document.getElementById('storelocationsmap'), mapOptions);
directionsDisplay.setMap(map);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: jQuery( '#stores li' ).find( 'h2' ).html()
})
}
function calcRoute() {
var myLatlng = new google.maps.LatLng(jQuery( '#stores li' ).data( 'latitude' ), jQuery( '#stores li' ).data( 'longitude' ));
var start = document.getElementById('start').value;
var end = myLatlng;
var request = {
origin:start,
destination:end,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment