Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Function to draw directions, call it whenever you want to show directions. You can pass some variables to it, and use them inside, to decide which markers will be start, end and waypts.</p> <pre><code>function calcRoute() { var startpt = yourstartlatlng; var endpt = yourendlatlng; var waypts = [] //your waypts array, if there are more than 1 point var request = { origin:startpt, destination:endpt, waypoints: waypts, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); } </code></pre> <p>Example from here: <a href="http://code.google.com/intl/pl-PL/apis/maps/documentation/javascript/examples/directions-simple.html" rel="nofollow">Google Maps Api</a></p> <p><strong>EDIT:</strong> When you have an array in php called waypts, and you want to have these values in javascript, you need to pass them to java. Its kinda messy, but thats the only way i know:</p> <pre><code>&lt;script type="text/javascript"&gt; var waypts = []; &lt;?php $waypts= array(1, 2, 3, 4); //&lt;-- your array, can be called like that, or just have values inside already for($i = 0; $i &lt; sizeof($waypts); $i++){ ?&gt; waypts[&lt;?php echo $i; ?&gt;] = &lt;?php echo $waypts[$i]; ?&gt;; //php is interpreted before java, when site will load, these values will be inside java "waypts" variable. &lt;?php } ?&gt; alert(""+waypts[1]); &lt;/script&gt; </code></pre> <p>That code will put your php variables/array into java array (alert is just to check if it did the job, you can delete it, once you understand the code). Then you can use these variables however you want. PHP is interpreted earlier than java, so in site code you will get waypts[0] = 1; cuz php code will be already replaced by values from array.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload