0

我是谷歌地图的新手,在互联网上的论坛中搜索和研究后,我无法获得这项工作。基于谷歌地图的原始代码,我不想绘制具有 2 条不同颜色的不同飞行路径的折线地图。

我正在尝试更改的原始代码:

function initialize() {
  var myLatLng = new google.maps.LatLng(0, -180);
  var mapOptions = {
    zoom: 3,
    center: myLatLng,
    mapTypeId: google.maps.MapTypeId.TERRAIN
  };

  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

  var flightPlanCoordinates = [
      new google.maps.LatLng(37.772323, -122.214897),
      new google.maps.LatLng(21.291982, -157.821856),
      new google.maps.LatLng(-18.142599, 178.431),
      new google.maps.LatLng(-27.46758, 153.027892)
  ];
  var flightPath = new google.maps.Polyline({
    path: flightPlanCoordinates,
    strokeColor: '#FF0000',
    strokeOpacity: 1.0,
    strokeWeight: 2
  });

  flightPath.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);

感谢您的帮助。

4

1 回答 1

0

你需要另一个google.maps.Polyline()

...
var flightPlanCoordinates = [
      new google.maps.LatLng(37.772323, -122.214897),
      new google.maps.LatLng(21.291982, -157.821856),
      new google.maps.LatLng(-18.142599, 178.431),
      new google.maps.LatLng(-27.46758, 153.027892)
  ];
  var flightPath = new google.maps.Polyline({
    path: flightPlanCoordinates,
    strokeColor: '#FF0000',
    strokeOpacity: 1.0,
    strokeWeight: 2
  });

  var flightPlanCoordinates2 = [
      new google.maps.LatLng(37.772323, -122.214897),
      new google.maps.LatLng(-27.46758, 153.027892)
      ];
  var flightPath2 = new google.maps.Polyline({
    path: flightPlanCoordinates2,
    strokeColor: '#FF00FF',
    strokeOpacity: 1.0,
    strokeWeight: 2
  });

  flightPath.setMap(map);
  flightPath2.setMap(map);  

...

于 2013-08-06T11:51:47.553 回答