Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show arrow for direction of a person who is moving when we are getting its coordinate in google map api

I am new to google map api and I have a particular use case where I am having coordinates(latitude and longitude) of a moving person and I want to show it in map along with direction, So far, I have tried this

  • html file

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

the output that I'm getting ishere.

how can I show the direction in this code because in my real scenario I will have user coordinate only?

like image 738
Alok Agarwal Avatar asked Oct 04 '22 06:10

Alok Agarwal


1 Answers

This can't be achieved by using the visualization-API, because you must be able to draw the arrows on the map(but you don't have access to the google.maps.Map-instance at all).

With the maps-JS-API it's not hard to implement, by using a IconSequence you may draw symbols on a PolyLine , e.g. an arrow(which will be rotated automatically into the right direction)

Demo: http://jsfiddle.net/doktormolle/V3gMT/

like image 192
Dr.Molle Avatar answered Oct 07 '22 18:10

Dr.Molle