如何在拉特隆上画路基

时间:2017-06-27 17:48:28

标签: javascript java android google-maps dictionary

我有一个lat lon列表,这是一个道路的位置集合,我想在画布上绘制它,

我从这里尝试了一些解决方案

[https://www.codeproject.com/Questions/626899/Converting-Latitude-And-Longitude-to-an-X-Y-Coordi][1]

但我仍然无法画路  这是lat lon list:

[35.6350019, 139.761, 35.634935, 139.761, 35.6343889, 139.7610111, 35.6341389, 139.761, 35.6339167, 139.7609544, 35.6336758, 139.7608861, 35.6335278, 139.7608294, 35.6334167, 139.76075, 35.6332592, 139.7606136, 35.6331667, 139.7605111, 35.6330647, 139.7603636, 35.6329722, 139.7601817, 35.6329072, 139.76, 35.6328703, 139.7598408, 35.6328333, 139.759625, 35.6328333, 139.7594544, 35.6328425, 139.7592839, 35.6328517, 139.7591475, 35.6328889, 139.7590111, 35.6329536, 139.7588294, 35.6330369, 139.7586817, 35.6331389, 139.7585111, 35.6332314, 139.7583975, 35.6333333, 139.7582839, 35.6334167, 139.7582158, 35.6335461, 139.7581361, 35.6336203, 139.7580908, 35.6337406, 139.7580453, 35.6338611, 139.7580111, 35.634, 139.7579886, 35.6341111, 139.7579886, 35.6342314, 139.758, 35.6343517, 139.7580339, 35.6344814, 139.7580908, 35.6345925, 139.7581475, 35.6347036, 139.7582158, 35.6348056, 139.7583067, 35.6349072, 139.7584203, 35.6349906, 139.7585453, 35.6350739, 139.7586817, 35.6351389, 139.7588181, 35.6352128, 139.7590453, 35.6352406, 139.7591817, 35.6352683, 139.7593522, 35.6352778, 139.7595225, 35.6352778, 139.7597044, 35.6352592, 139.7598522, 35.6352314, 139.7600225, 35.6351758, 139.7602725, 35.6350278, 139.7608975, 35.6350019, 139.761]

1 个答案:

答案 0 :(得分:1)

您必须绘制折线并将其放在地图上。

检查this example

<div id="map"></div>
<script>

  // This example creates a 2-pixel-wide red polyline showing the path of William
  // Kingsford Smith's first trans-Pacific flight between Oakland, CA, and
  // Brisbane, Australia.

  function initMap() {
    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 3,
      center: {lat: 0, lng: -180},
      mapTypeId: 'terrain'
    });

    var flightPlanCoordinates = [
      {lat: 37.772, lng: -122.214},
      {lat: 21.291, lng: -157.821},
      {lat: -18.142, lng: 178.431},
      {lat: -27.467, lng: 153.027}
    ];
    var flightPath = new google.maps.Polyline({
      path: flightPlanCoordinates,
      geodesic: true,
      strokeColor: '#FF0000',
      strokeOpacity: 1.0,
      strokeWeight: 2
    });

    flightPath.setMap(map);
  }
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
</script>

这是硬编码的,这通常不是一个实际的解决方案。因此,我建议编写一些php代码来填充MySQL数据库中的lat / lon点列表。

注意:您还可以将底图更改为自定义底图。在this SO answer中,您会找到显示白色基座的代码,没有控件(注意,您不会有大陆,海洋,河流,湖泊等 - 只是白色背景)。