-1

i am new in Javasricpt and i am developing an application using Google Maps API. I'm trying to call a javascript function from onclick event but is not being called. Please if anyone see any errors or something i am missing let me know, I will appreciated. Below is my code.

This is javascript code:

 <script>
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var Center=new google.maps.LatLng(18.210885,-67.140884);

function initialize() {
  directionsDisplay = new google.maps.DirectionsRenderer();
  var properties = {
    center:Center,
    zoom:18,
    mapTypeId:google.maps.MapTypeId.SATELLITE
  };
  map=new google.maps.Map(document.getElementById("map"), properties);
  directionsDisplay.setMap(map);
  }
function makeRoute() {
    var start = new google.maps.LatLng(18.210885,-67.140884);
    var end =new google.maps.LatLng(18.2098150,-67.1418260);
    var request = {
      origin:start,
      destination:end,
      travelMode: google.maps.TravelMode.WALKING
      };

    directionsService.route(request, function(result, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(result);
    } else { alert("couldn't get directions:"+status); }
    });
}

</script>

This is my form:

 <form method="post" action="">
          <table border="0px" style="border-radius:5px; border-color: #888888; background-color: #FFFFFF; box-shadow: 5px 5px 5px #888888;"><tr>
          <td><b>Get directions:</b></font><br/></td>
          </tr><tr><td align="right">Building:</td><td>
            <select name="building">
              <option value="#" default >Select</option>
              <option value="monzon">Monzon</option>
            </select></td></tr><tr>
          <td align="right">Room:</td>
          <td><input type="text" name="room" placeholder="eg. 208B / CH 116" ></td>
          </tr><tr><td></td>
          <td align="right" ><input id="submit" type="submit" value="submit" onclick="makeRoute()"></td></tr></table>
        </form>
4

1 回答 1

0

工作示例

您需要在此处返回 false:

<td align="right" ><input id="submit" type="submit" value="submit" onclick="makeRoute(); return false;"></td></tr></table>

防止页面重新加载并显示空地图。

于 2013-02-02T21:04:42.147 回答