2

Is it possible to show Google Maps directions in a PDF with DOMPDF? I tried it with the JavaScript Google Maps API and embed the required files and called the function inline, but it doesn't work. Any other solutions?

<script type="text/javascript">
    $(document).ready(function() {
        initialize();
        calcRoute("Innsbruck", "Salzburg");
    });
</script>

main.js:

var geocoder;
var directionDisplay;
var directionsService = new google.maps.DirectionsService();

function initialize() {
    geocoder = new google.maps.Geocoder();

    var latlng = new google.maps.LatLng(51.764696, 5.526042);
    directionDisplay = new google.maps.DirectionsRenderer();

    var config = {
        zoom: 14,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        mapTypeControl: false
    }

    var map = new google.maps.Map(document.getElementById("map_canvas"), config);
    directionDisplay.setMap(map);
    directionDisplay.setPanel(document.getElementById("directionsPanel"));

    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        title: "My Location"
    });
}

function calcRoute(r_start, r_end) {    
    var start = r_start;
    var end = r_end;
    var request = {
        origin: start,
        destination: end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    }

    directionsService.route(request, function(response, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            directionDisplay.setDirections(response);
        }
    });
}
Mirza Sisic
  • 2,401
  • 4
  • 24
  • 38
Mathis Hüttl
  • 281
  • 4
  • 18
  • It's possible with Google static map but you will not be able to dynamically change your map @Mathis Hüttl – simon Mar 25 '16 at 08:37
  • @simon that sound good, i dont want to dynamically change the map. how can i embed the directions? via iframe? – Mathis Hüttl Mar 25 '16 at 08:43
  • Read this link http://stackoverflow.com/questions/3922086/google-map-static-drawing-route-instead-of-straight-line @Mathis Hüttl – simon Mar 25 '16 at 08:50
  • @simon is it possible to get such like this with static maps? https://s13.postimg.org/ou01y1eav/Unbenannt.jpg – Mathis Hüttl Mar 25 '16 at 09:01
  • dompdf is unable to process JavaScript so it will not be able to render the standard Google Maps interface. For something like that you could use a headless browser such as [PhantomJS](http://phantomjs.org). – BrianS Mar 25 '16 at 13:33

0 Answers0