Google Maps Track Color

Does anyone know how I can change the color of one of the tracks I am importing into google maps? I have two tracks importing one of which I want to be blue the other red. I am using google maps to pull the .gpx files as kml layers, is this the best way of doing this?

Any help appreciated.

heres the code I have (found this on a site for pulling in the file as a gpx - new to all the google maps coding):

<script type="text/javascript">
  function initialize() {
    var myOptions = {
      center: new google.maps.LatLng(-34.397, 150.644),
      zoom: 8,
      mapTypeId: google.maps.MapTypeId.TERRAIN
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);

    var ctaLayer = new google.maps.KmlLayer('http://www.walkwithjon.co.uk/ForTor.gpx');

    var ctaLayer2 = new google.maps.KmlLayer('http://www.walkwithjon.co.uk/Tor2.gpx');


ctaLayer2.setMap(map);

ctaLayer.setMap(map);

   var lines = xmlDoc.documentElement.getElementsByTagName("trkpt");
      // read each line
      for (var a = 0; a < lines.length; a++) {
        // get any line attributes
        var colour = lines[a].getAttribute("color");
        var width  = parseFloat(lines[a].getAttribute("width"));
        // read each point on that line
        var points = lines[a].getElementsByTagName("point");
        var pts = [];
        for (var i = 0; i < points.length; i++) {
           pts[i] = new GLatLng(parseFloat(points[i].getAttribute("lat")),
                               parseFloat(points[i].getAttribute("lng")));
        }
        map.addOverlay(new GPolyline(pts,colour,width));
      }


  }


</script>

无论文件xmlDoc引用应该有一个名为color的属性,您可以编辑(我假设颜色是十六进制值)。

链接地址: http://www.djcxy.com/p/23350.html

上一篇: 在Google Maps API v3中包含多个标记的中心地图

下一篇: Google地图轨道颜色