簡體   English   中英

我無法使用gmaps.js繪制路徑

[英]I can't draw path with using gmaps.js

我使用gmaps.js示例和文檔嘗試在Google地圖上繪制路徑,但未繪制任何內容。

我的代碼在這里:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Show Vehicles</title>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  <script src="http://maps.google.com/maps/api/js?sensor=true"></script>
  <script src="js/gmaps.js"></script>
    <script type="text/javascript">
    var map;
    $(document).ready(function(){

      map = new GMaps({
        div: '#map',
        lat: 53.361320,
        lng: -6.505633,
        click: function(e){
          console.log(e);
        }
      });
      path = [[53.361320,-6.505633],[53.361330,-6.505643],[53.361335,-6.505650],[53.361343,-6.505652],[53.361352,-6.505668],[53.361347,-6.505672],[53.361342,-6.505688],[53.361347,-6.505700],[53.361337,-6.505717],[53.361352,-6.505722],[53.361342,-6.505735],[53.361357,-6.505740],[53.361372,-6.505753],[53.361383,-6.505758]];

      map.drawPolyline({
        path: path,
        strokeColor: '#131540',
        strokeOpacity: 0.6,
        strokeWeight: 6
      });
    });
  </script>
</head>
<body>
    <div id="map"></div>
</body>
</html>

請幫我

您的代碼實際上看起來正確(並且一個快速演示似乎至少在我的瀏覽器上顯示了它的功能)。 我認為您需要設置zoom比例才能看到Polyline (這是一條很小的線),可能像這樣( 演示 )):

map = new GMaps({
  div: '#map',
  zoom: 19,
  lat: 53.361320,
  lng: -6.505633,
  click: function(e){
    console.log(e);
  }
});

您的path由數字數組組成。 它應該是google.maps.LatLng的數組,然后可以將其傳遞給maps.drawPolyline 請參閱https://developers.google.com/maps/documentation/javascript/examples/polyline-simple

我找到了問題,我沒有為此設置css,我可以看到映射的地圖

h1{
font-size:2em;
}

body{
  font-family: 'Droid Sans', 'Helvetica', Arial, sans-serif;
  margin:5px;
}
#map{
  display: block;
  width: 95%;
  height: 350px;
  margin: 0 auto;
  -moz-box-shadow: 0px 5px 20px #ccc;
  -webkit-box-shadow: 0px 5px 20px #ccc;
  box-shadow: 0px 5px 20px #ccc;
}
#map.large{
  height:500px;
}

.overlay{
  display:block;
  text-align:center;
  color:#fff;
  font-size:60px;
  line-height:80px;
  opacity:0.8;
  background:#4477aa;
  border:solid 3px #336699;
  border-radius:4px;
  box-shadow:2px 2px 10px #333;
  text-shadow:1px 1px 1px #666;
  padding:0 4px;
}

.overlay_arrow{
  left:50%;
  margin-left:-16px;
  width:0;
  height:0;
  position:absolute;
}
.overlay_arrow.above{
  bottom:-15px;
  border-left:16px solid transparent;
  border-right:16px solid transparent;
  border-top:16px solid #336699;
}
.overlay_arrow.below{
  top:-15px;
  border-left:16px solid transparent;
  border-right:16px solid transparent;
  border-bottom:16px solid #336699;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM