Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps API: find a route between two points in Israel
    primarykey
    data
    text
    <p>I am trying to find a route between two points i enter manually at my html page but i get ZERO_RESULTS return value.</p> <p>The users enters two locations src_address = "Tel Aviv" and dst_address = "Haifa".</p> <p>i get their geometric location by calling geocoder.geocode twice for each address. then set : src_latlng = results[0].geometry.location; dst_latlng = results[0].geometry.location;</p> <p>however, when asking for router i get ZERO_RESULTS:</p> <p>here is the code:</p> <pre><code> &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;img src="globe123.jpg" width="72" height="75"/&gt; &lt;head&gt; &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no"/&gt; &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"/&gt; &lt;title&gt;Google Maps JavaScript API v3 Example: Geocoding Simple&lt;/title&gt; &lt;link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /&gt; &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; var directionDisplay; var directionsService = new google.maps.DirectionsService(); var geocoder; var map; var geodesic; var poly; var src_latlng; var dst_latlng; function initialize() { directionsDisplay = new google.maps.DirectionsRenderer(); geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(-34.397, 150.644); var myOptions = { zoom: 8, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var polyOptions = { strokeColor: '#FF0000', strokeOpacity: 1.0, strokeWeight: 3 } poly = new google.maps.Polyline(polyOptions); poly.setMap(map); directionsDisplay.setMap(map); // Add a listener for the click event //google.maps.event.addListener(map, 'click', addLocation); } function codeAddress() { var src_address = document.getElementById("SRC_ADDR").value; var dst_address = document.getElementById("DST_ADDR").value; geocoder.geocode( { 'address': src_address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); var path = poly.getPath(); path.push(results[0].geometry.location); src_latlng = results[0].geometry.location; var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }); } else { alert("Geocode was not successful for the following reason: " + status); } }); geocoder.geocode( { 'address': dst_address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); map.setZoom(8); var path = poly.getPath(); path.push(results[0].geometry.location); dst_latlng = results[0].geometry.location; var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }); calcRoute(); } else { alert("Geocode was not successful for the following reason: " + status); } }); } function calcRoute() { var start = src_latlng; var end = dst_latlng; var request = { origin:start, destination:end , travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(result, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(result); } else { alert(status); } }); } &lt;/script&gt; &lt;/head&gt; &lt;body onload="initialize()"&gt; &lt;div style="text-align:left"&gt; Source: &lt;input id="SRC_ADDR" type="textbox" value="Tel-Aviv, Israel"&gt; Destination: &lt;input id="DST_ADDR" type="textbox" value="Haifa, Israel"&gt; &lt;input type="button" value="Calculate Travel Time" onclick="codeAddress()"&gt; &lt;/div&gt; &lt;div id="map_canvas" style="height:40%;width:40%;top:120px"&gt;&lt;/div&gt; &lt;!-- &lt;div id="map_canvas" style="width: 320px; height: 480px;"&gt;&lt;/div&gt; --&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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