5

我是 google map api 的新手,我有一个特殊的用例,我有一个移动的人的坐标(纬度和经度),我想在地图中显示它以及方向,到目前为止,我已经尝试过了

  • .html 文件

    <!DOCTYPE html>
    <html>
    <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
    
    google.load("visualization", "1", {packages:["map"]});
    google.setOnLoadCallback(drawMap);
    function drawMap() {
    var arr = [
    ['Lat', 'Lon','data'],
    [12.938419, 77.62224, '0'],
    [12.938494, 77.622377, '0'],
    [12.938369, 77.622449, '0'],
    [12.938345, 77.622521, '0'],
    [12.938322, 77.622575, '0'],
        [12.938346, 77.622631, '0'],
    [12.938306, 77.622648, '0'],
    [12.938299, 77.622695, '0'],
    [12.938254, 77.622715, '0'],
    [12.938242, 77.622761, '0'],
    [12.938227, 77.622805, '0'],
    [12.93819, 77.622792, '0'],
    [12.938138, 77.622837, '0'],
    [12.938129, 77.622887, '0'],
    [12.938103, 77.622949, '0'],
    [12.938066, 77.622989, '0'],
    [12.938006, 77.622966, '0'],
    [12.937933, 77.623001, '0'],
    [12.937976, 77.623073, '0'],
    [12.937954, 77.623128, '0'],
    [12.937912, 77.623111, '0'],
    [12.937882, 77.623034, '0'],
    [12.937933, 77.623001, '0'],
    [12.938006, 77.622966, '0'],
    [12.937921, 77.62293, '0']
    ]
    var data = google.visualization.arrayToDataTable(arr);
        var map = new google.visualization.Map(document.getElementById('map_div'));
        map.draw(data, {showTip: true, showLine: true, mapType: 'normal', useMapTypeControl:true, enableScrollWheel:true});
    
    }
        </script>
            </head>
            <body>
            <div id="map_div" style="width: 800px; height: 600px"></div>
            </body>
            </html>
    

我得到的输出是这里.

我如何在这段代码中显示方向,因为在我的真实场景中我只有用户坐标?

4

1 回答 1

4

这不能通过使用可视化 API 来实现,因为您必须能够在地图上绘制箭头(但您根本无法访问 google.maps.Map-instance)。

使用 maps-JS-API 实现起来并不难,通过使用 aIconSequence您可以在 PolyLine 上绘制符号,例如箭头(将自动旋转到正确的方向)

演示:http: //jsfiddle.net/doktormolle/V3gMT/

于 2013-08-13T15:27:41.557 回答