-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_tracks.php
125 lines (111 loc) · 3.38 KB
/
my_tracks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
require_once('db.4wd.inc.php');
$res = pg_query($db, "SELECT ST_AsText(ST_PointN(T.wkb_geometry, 1)) FROM my_tracks AS T WHERE T.id = ".$_GET['track']);
$row = pg_fetch_row($res);
$txt = substr($row[0],6);
$etxt = strstr($txt, ' ');
$txt = substr_replace($txt, '', strpos($txt, ' '));
$etxt = substr_replace($etxt, '', -1);
$etxt = substr_replace($etxt, '', 0, 1);
$lat = $etxt;
$lon = $txt;
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $lon; ?>);
var myOptions = {
zoom: 13,
center: latlng,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var track_path = [
<?php
$res = pg_query($db, "SELECT ST_AsText(ST_PointN(T.wkb_geometry, generate_series(1, ST_NPoints(T.wkb_geometry)))) FROM my_tracks AS T WHERE T.id = ".$_GET['track'].";");
while($row = pg_fetch_row($res))
{
$txt = substr($row[0],6);
$etxt = strstr($txt, ' ');
$txt = substr_replace($txt, '', strpos($txt, ' '));
$etxt = substr_replace($etxt, '', -1);
$etxt = substr_replace($etxt, '', 0, 1);
$lat = $etxt;
$lon = $txt;
?>
new google.maps.LatLng(<?php echo $lat; ?>,<?php echo $lon; ?>),
<?php
}
?>
];
var track = new google.maps.Polyline({
path: track_path,
strokeColor: "#00FF00",
strokeOpacity: 1.0,
strokeWeight: 2,
title: "track",
map: map
});
track.setMap(map);
<?php
$res = pg_query($db, "SELECT T.*,ST_Length(T.wkb_geometry),ST_AsText(ST_PointN(T.wkb_geometry,1)),Distance(T.wkb_geometry,T2.wkb_geometry) FROM my_tracks AS T, my_tracks AS T2 WHERE T2.id = ".$_GET['track']." AND T.id != T2.id AND Distance(T.wkb_geometry,T2.wkb_geometry) < 1 ORDER BY Distance(T.wkb_geometry,T2.wkb_geometry) ASC;");
$i = 0;
while($row = pg_fetch_row($res))
{
$tuid = $row[0];
$track_res = pg_query($db, "SELECT ST_AsText(ST_PointN(T.wkb_geometry, generate_series(1, ST_NPoints(T.wkb_geometry)))) FROM my_tracks AS T WHERE T.id = ".$row[0].";");
?>
var track_path<?php echo $i; ?> = [
<?php
while($track_row = pg_fetch_row($track_res))
{
$txt = substr($track_row[0],6);
$etxt = strstr($txt, ' ');
$txt = substr_replace($txt, '', strpos($txt, ' '));
$etxt = substr_replace($etxt, '', -1);
$etxt = substr_replace($etxt, '', 0, 1);
$lat = $etxt;
$lon = $txt;
?>
new google.maps.LatLng(<?php echo $lat; ?>,<?php echo $lon; ?>),
<?php
}
?>
];
var trackPoint = new google.maps.Marker({
position: new google.maps.LatLng(<?php echo $lat; ?>,<?php echo $lon; ?>),
map: map,
title: "<?php echo $tuid; ?>"
});
var track<?php echo $i; ?> = new google.maps.Polyline({
path: track_path<?php echo $i; ?>,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2,
title: "track<?php echo $i; ?>",
map: map
});
track<?php echo $i; ?>.setMap(map);
<?php
$i++;
}
?>
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>