Я хочу отфильтровать свои точки 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'] . '");';
}
?>
ура!