javascript - Google Maps API v3 validate place -


is possible validate if place exist? in example below when fill "wkjdbvkwe" destination place, nothing.. want show error message , don't know how validate if destination =! real place.

var source, destination;      var directionsdisplay;      var directionsservice = new google.maps.directionsservice();      google.maps.event.adddomlistener(window, 'load', function () {          new google.maps.places.searchbox(document.getelementbyid('txtdestination'));          directionsdisplay = new google.maps.directionsrenderer({ 'draggable': true });      });        function getroute() {          //*********directions**********************//          source = "Čadca, slovensko";          destination = document.getelementbyid("txtdestination").value;            var request = {              origin: source,              destination: destination,              travelmode: google.maps.travelmode.driving          };          directionsservice.route(request, function (response, status) {              if (status == google.maps.directionsstatus.ok) {                  directionsdisplay.setdirections(response);              }          });            //*********distance , duration**********************//          var service = new google.maps.distancematrixservice();          service.getdistancematrix({              origins: [source],              destinations: [destination],              travelmode: google.maps.travelmode.driving,              unitsystem: google.maps.unitsystem.metric,              avoidhighways: false,              avoidtolls: false          }, function (response, status) {              if (status == google.maps.distancematrixstatus.ok && response.rows[0].elements[0].status != "zero_results") {                  var distance = response.rows[0].elements[0].distance.text;                  var dvdistance = document.getelementbyid("distance");                  dvdistance.innerhtml = "";                  dvdistance.innerhtml += distance;                } else {                  alert("nie je možné vypočítať vzdialenosť");              }          });      }
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places.js"></script>    destination: <input type="text" id="txtdestination" onblur="getroute()"  />  <br/>  <span id="distance"></span>

thank you!

add else if (status == google.maps.directionsstatus.ok)

 if (status == google.maps.directionsstatus.ok) {             directionsdisplay.setdirections(response);  } else {     alert("can't create directions:" + status);  } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -