Browse Source

Initial

master
Léo Serre 2 years ago
commit
4e6c027acb
4 changed files with 101 additions and 0 deletions
  1. +48
    -0
      geojson.php
  2. +11
    -0
      index.php
  3. +1
    -0
      positions.txt
  4. +41
    -0
      rename_that_file.php

+ 48
- 0
geojson.php View File

@@ -0,0 +1,48 @@
<?php
/*
* Title: CSV to GeoJSON
* Notes: Convert a comma separated CSV file of points with x & y fields to GeoJSON format, suitable for use in OpenLayers, Leaflet, etc. Only point features are supported.
* Author: Bryan R. McBride, GISP
* Contact: bryanmcbride.com
* GitHub: https://github.com/bmcbride/PHP-Database-GeoJSON
*/
# Read the CSV file
$csvfile = 'positions.txt';
$handle = fopen($csvfile, 'r');
# Build GeoJSON feature collection array
$geojson = array(
'type' => 'FeatureCollection',
'features' => array()
);
# Loop through rows to build feature arrays
$header = NULL;
while (($row = fgetcsv($handle, 1000, ',')) !== FALSE) {
if (!$header) {
$header = $row;
} else {
$data = array_combine($header, $row);
$properties = $data;
# Remove x and y fields from properties (optional)
unset($properties['x']);
unset($properties['y']);
$feature = array(
'type' => 'Feature',
'geometry' => array(
'type' => 'Point',
'coordinates' => array(
$data['x'],
$data['y']
)
),
'properties' => $properties
);
# Add feature arrays to feature collection array
#array_push($geojson['features'], $feature);
}
}
array_push($geojson['features'], $feature);
fclose($handle);
header('Content-type: application/json');
header("Access-Control-Allow-Origin: *");
echo json_encode($geojson, JSON_NUMERIC_CHECK);
?>

+ 11
- 0
index.php View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>HRP Geolocator</title>
</head>
<body>
<h1>Rien à voir ici.</h1>
<p>Il n'y a rien de spécial à voir ici.</p>
</body>
</html>

+ 1
- 0
positions.txt View File

@@ -0,0 +1 @@
date,y,x

+ 41
- 0
rename_that_file.php View File

@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>HRP Geolocator</title>
<style type="text/css">* { border: 0; margin: 0; padding: 0; width: 100%; height: 100%;}</style>
</head>
<?php if( isset($_POST['button']) ) {
if( $_POST['lat'] != 0 && $_POST['lon'] != 0)
file_put_contents("positions.txt", date("d/m/o H:i", time()+7200).",".$_POST['lat'].",".$_POST['lon']."\n", FILE_APPEND); ?>
<body>
<p>Position added.</p>
</body>
<?php }
else { ?>
<body onload="getLocation()">
<form method="post">
<input type="hidden" name="lat" id="lat" value="0">
<input type="hidden" name="lon" id="lon" value="0">
<button type="submit" name="button" id="button">Waiting for geolocation...</button>
</form>

<script>
var x = document.getElementById("button");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
document.getElementById("lat").value = position.coords.latitude;
document.getElementById("lon").value = position.coords.longitude;
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
</body>
<?php } ?>
</html>

Loading…
Cancel
Save