0
我想通過計算點之間的距離來過濾我的GPS點(減少顯示的點數),如果距離小於300米,則不要將下一個點添加到地圖。地圖點過濾距離
這是我目前的JavaScript來創建標記和折線
var json = jQuery.parseJSON(data);
jQuery("#gMap").gmap3({ action: 'clear' });
jQuery(".marker").remove();
var counts = 0;
jQuery.each(json, function(i, item) {
var polyArray=[];
var name = item.name;
var userId = item.data.user;
jQuery.each(item.data.data, function(i, nav) {
var ts = nav.timestamp;
var lat = nav.latitude;
var long = nav.longitude;
if (lat != null && long != null) {
addMarker(name, counts = counts + 1, ts, lat, long, userId);
polyArray.push([ lat, long]);
}
addPolyline(polyArray, get_random_color());
});
})
這是我的老版本的PHP,我用來實現上述 - 我怎樣才能達到同樣的在我的javascript?
<?php
$old_lat = $old_long = "0";
$data = array();
foreach($history['data'] as $i => $record) {
$distance = distance($record['latitude'], $record['longitude'], $old_lat, $old_long, "V");
if($distance >= $_SESSION['same_position']) {
$last_i = $i;
$data[$i] = $record;
$old_lat = $record['latitude'];
$old_long = $record['longitude'];
} else {
$data[$last_i]['to_timestamp'] = $record['timestamp'];
$old_lat = $record['latitude'];
$old_long = $record['longitude'];
}
}
foreach($data as $record) {
echo 'add(jQuery(this), number += 1, "' . $record['timestamp'] . '", "' . $name . '", "' . $history['user'] . '", "' . $record['latitude'] . '", "' . $record['longitude'] . '", "' . $record['to_timestamp'] . '");';
}
?>
乾杯!
你有一個問題點計算之間的實際距離,或者只是在JavaScript實現的呢? – Douglas 2012-04-01 08:30:15
我可以用google.maps.geometry.spherical.computeDistanceBetween()來計算這個差別。它只是使JavaScript版本工作。 – 2012-04-01 16:13:25