我的第二张地图v3没有显示

时间:2015-03-08 16:36:21

标签: javascript android html

你好朋友我一直在研究这个项目地图v3在地图上显示方向但是,我不明白为什么地图没有加载。我几乎尝试了所有我知道的东西,但没有成功。请查看代码,看看是否有什么东西阻止地图加载。

    <!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Street View service</title>
    <style>
      html, body {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
      #mode{
       height:5%;
       width:60%
       margin-left:0%;
       margin-right:0%;
       margin-top:5%;
       margin-bottom:0%
      }
      #autocomplete {
        font-size:11pt;
        align:center;
        width: 60%;
        margin-left:35%;
        margin-right:5%;
        margin-top:1%;
        margin-bottom:0%
       }
       #autocomplete1 {
        font-size:11pt;
        align:center;
        width: 60%;
        margin-left:35%;
        margin-right:5%;
        margin-top:1%;
        margin-bottom:0%
      }
      #from {
      margin-top:1%;
      margin-left:0%;
      margin-right:0%;
      margin-bottom:0%
      }
      #to {
      margin-top:1%;
      margin-left:0%;
      margin-right:0%;
      margin-bottom:0%
      }
      #locationField {
      margin-left:0%;
      margin-right:0%;
      margin-top:1%;
      margin-bottom:0%
      }
      #locationField1 {
      margin-left:0%;
      margin-right:0%;
      margin-top:1%;
      margin-bottom:0%
      }
      #button {
       align:center;
       margin-top:1%;
       margin-right:5%;
       margin-bottom:0%;
       margin-left:35%;
       width:60%;
       height:8%
      }
       #map-canvas {
       margin-top:1%;
       margin-right:0%;
       margin-bottom:0%;
       margin-left:0%;
       width: 100%;
       height: 30%
       }
   </style>

     <link type="text/css" rel="stylesheet"          href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
     <script src="https://maps.googleapis.com/maps/api/js? v=3.exp&signed_in=true&libraries=places"></script>
    <script>

    var directionsDisplay;
    var directionsService = new google.maps.DirectionsService();
    var map;


   function initialize() {
   directionsDisplay = new google.maps.DirectionsRenderer();
   var chicago = new google.maps.LatLng(41.850033, -87.6500523);
   var mapOptions = {
    zoom:14,
    center: chicago,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    streetViewControl: false
      }
   map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
   directionsDisplay.setMap(map);

    }


    function searchDirection() {
    var start = document.getElementById("autocomplete").value;
    var end = document.getElementById("autocomplete1").value;
    var selectedMode = document.getElementById("mode").value;

    var request = {
    origin:start,
    destination:end,
    travelMode: google.maps.TravelMode.[selectedMode]

   };
   directionsService.route(request, function(result, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(result);
    }
   });
   }

    </script>
    </head>
    <body onload="initialize();">
    <div id="text" style="width: 100%; height: 50%;">
    <div>
   <strong>Direction By : </strong>
   <select id="mode" onchange="calcRoute();">
  <option value="DRIVING">Driving</option>
  <option value="WALKING">Walking</option>
  <option value="BICYCLING">Bicycling</option>
  <option value="TRANSIT">Transit</option>
  </select>
  </div>

  <div id="locationField">
      <strong id="from">From : </strong>
      <input id="autocomplete" placeholder="Enter Starting Point"
             onFocus="geolocate()" type="text"></input>
  </div>

  <div id="locationField1">
      <strong id="to">To : </strong>
      <input id="autocomplete1" placeholder="Enter Destination Point"
             onFocus="geolocate()" type="text"></input>
   </div>

   <input id="button" type="button" name="test" value="Search"  style=" font-size:12pt; background-color:#00FF00; color:#A9F5F2;" onclick="searchDirection()">

   </div>

   <div id="map-canvas"></div>

  </body>
</html>

0 个答案:

没有答案