javascript - 当我们在 google map api 中获取坐标时,如何显示移动的人的方向箭头

标签 javascript google-maps-api-3

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

  • 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>
    

我得到的输出是 here .

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

最佳答案

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

使用 maps-JS-API 不难实现,通过使用 IconSequence你可以draw symbols on a PolyLine ,例如一个箭头(会自动旋转到正确的方向)

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

关于javascript - 当我们在 google map api 中获取坐标时,如何显示移动的人的方向箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18205998/

相关文章:

javascript - 哪个 HTTP 代码应该作为状态返回?

javascript - 在html页面上设计弹出窗口

javascript - 使用 fabric.js 的 loadad SVG 中的图像大小错误

javascript - 谷歌地图 : Can't get InfoWindow to display

javascript - Google Maps API v3 map.fitbounds(bounds) 设置 map 缩放不正确的问题

javascript - 在循环中添加事件点击时,谷歌地图标记崩溃

javascript - Node.js 服务器如何访问 ajax 请求的数据?

javascript - 如果 jQuery 的数据属性为真

android - 我的应用应该多久使用 GPS 更新一次用户的位置?每 1 秒是矫枉过正还是罚款?

google-maps-api-3 - Google 地理编码 API - 印度保留地