3

我已经在地图上制作了路线。使用一些坐标生成的路线,这些坐标完成了附加信息(速度)。我希望当路线悬停时,会出现一个工具提示并在这些坐标处显示信息(速度)。我很困惑如何显示速度的工具提示。

<html>
<head>
   <title>Polyline Route v3 Example</title>
   <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3&amp;sensor=false"></script>
   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>   
   <script type="text/javascript">
    var locations = [
        {"speed":"13","lat":"-6.246192976751192","lon":"106.79324626922607"}, {"speed":"33","lat":"-6.245723710157699","lon":"106.79603576660156"}, {"speed":"23","lat":"-6.245723710157699","lon":"106.79796695709229"}, {"speed":"43","lat":"-6.243334710069922","lon":"106.79800987243652"},
        {"speed":"12","lat":"-6.245723810157699","lon":"106.79796725709229"}, {"speed":"1","lat":"-6.245723860157699","lon":"106.79796735709229"}, {"speed":"45","lat":"-6.245723890157699","lon":"106.79797755709229"}, {"speed":"21","lat":"-6.245723910157699","lon":"106.79797895709229"}
    ];
    var map;
    function createRouteMap(){
    var listRoute = [];
    for (var i = 0; i < locations.length; i++) {
        listRoute.push(new google.maps.LatLng(locations[i].lat, locations[i].lon));
    }
    var mapOptions = {
      zoom: 16,
      center: listRoute[Math.ceil(listRoute.length/2)],
      mapTypeId: google.maps.MapTypeId.ROADMAP,
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    showMap(listRoute);
    createMarkers(locations);
}

function showMap(listRoute){
    if((listRoute.length < 1) || (listRoute == null)){
        jQuery("#map_canvas").html('<div class="alert alert-info"> <strong>Empty Trail!</strong> This trip still has no trail </div>'+
        '<div class="btn-toolbar"> <p><code>The gps device </code>in the car still not sent position!</p> </div>');
    }else{
        var flightPath = new google.maps.Polyline({
            path: listRoute,
            strokeColor: "#FF0000",
            strokeOpacity: 5,
            strokeWeight: 3.7
        });
        flightPath.setMap(map);
    }
}

function createMarkers(locations) {
    for (var i = 0; i < locations.length; i++) {
        var point = locations[i];
        var myLatLng = new google.maps.LatLng(point.lat, point.lon);
        var marker = new google.maps.Marker({
            position: myLatLng,
            map: map,
            icon: 'greencirclemarker.png',
            title: point.speed
        });
    }
}

$(document).ready(function() {
    createRouteMap();
});

</script>
</head>
<body>
<div id="map_canvas" style="height:400px; border:1px 00f solid;"></div>
</body>
</html>
4

1 回答 1

3

您的“速度”与积分相关联。你有几个选择:

  1. 添加标记并在鼠标悬停时显示速度(或作为标记的工具提示)

  2. 使用自己的鼠标悬停事件处理程序将线的每一段渲染为单独的折线。您将需要指定如何将速度应用于线段。使用单个折线可以使用更复杂的方法,但是使用鼠标悬停事件可能会出现性能问题。

于 2013-03-15T20:54:01.727 回答