谷歌地图api跟踪设备

时间:2012-11-18 22:54:25

标签: javascript google-maps-api-3

基本上,我每次搬家都试图追踪我的位置。

我设法让下面的代码使用'click'监听器事件,只是为了测试它,我只是不确定我是如何以及如何使用正确的事件监听器:

function mapRoute(showPosition3, position){



var routeCoordinates = [new google.maps.LatLng(53.388639, -1.4785248000000002)];



  var polyOptions = {
    path: routeCoordinates,
    strokeColor: "#FF0000",
    strokeOpacity: 1.0,
    strokeWeight: 2
  }

 flightPath = new google.maps.Polyline(polyOptions);

 flightPath.setMap(map);

google.maps.event.addListener(map, 'click', addLatLng);

}


/**
 * Handles click events on a map, and adds a new point to the Polyline.
 * @param {MouseEvent} mouseEvent
 */
function addLatLng(event) {

  var path = flightPath.getPath();

  // Because path is an MVCArray, we can simply append a new coordinate
  // and it will automatically appear
  path.push(event.latLng);

  // Add a new marker at the new plotted point on the polyline.
  var marker = new google.maps.Marker({
    position: event.latLng,
    title: '#' + path.getLength(),
    map: map
  });

}

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

这涉及到很多细节。如果您不想从头编写自己的代码,可以使用属于GeolocationMarkerGoogle Maps API v3 Utility Library。它为您处理许多小细节。由于它是开源的,您也可以根据自己的需要进行修改。