新しいデータが挿入されるたびにトリガーされるイベントをJavaScriptで作成する方法を知りたいですか?
これは、Google マップでライブ トラッキングを使用できるようにするために必要です。
たとえば、これは地理位置情報のページで見つけたコードです。
function scrollMap(position)
{
// Scrolls the map so that it is centered at (position.coords.latitude,position.coords.longitude).
}
// Request repeated updates.
var watchId = navigator.geolocation.watchPosition(scrollMap);
function buttonClickHandler()
{
// Cancel the updates when the user clicks a button.
//I want to put my code in here so for example when I click button live tracking starts.
navigator.geolocation.clearWatch(watchId);
}
これは、データの配列を取得するために使用している私のコードです:
function initialize() {
var myLatLng = new google.maps.LatLng(0, 180);
var myOptions = {
zoom: 3,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var flightPlanCoordinates = [<?php echo implode(',', $coordinates) ?>];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
}
コードがデータベースに挿入されるたびに、コードを機能させて最後の結果を取得するにはどうすればよいですか? そして、私の質問の冒頭で提供されているGoogleコードの地図に表示してください。
データベースはmysqlで、ID、緯度、経度があります。
編集:
これは、データベースからすべてのデータを取得し、Google マップの配列に配置する PHP コードです。
$coordinates = array();
$result = dbMySql::Exec('SELECT Latitude,Longitude FROM data');
while ($row = mysqli_fetch_assoc($result))
$coordinates[] = 'new google.maps.LatLng(' . $row['Latitude'] . ', ' . $row['Longitude'] . ')';