Upload files to "/"

This commit is contained in:
2024-06-08 11:18:42 +02:00
parent 179fe23972
commit 74b3a39e62
2 changed files with 102 additions and 0 deletions

58
getLocation.php Normal file
View File

@@ -0,0 +1,58 @@
<?php
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
//$location = $_POST['latitude'];
//echo $location;
$lat = $_POST['latitude'];
$lon = $_POST['longitude'];
$latlon = "lat={$lat}&lon={$lon}";
//echo "url?";
//echo "posisjon?{$latlon}&maks_avstand=20&maks_antall=1&konnekteringslenker=true&detaljerte_lenker=true&srid=WGS84&trafikantgruppe=K";
// create a new cURL resource
$ch = curl_init();
$url = "https://nvdbapiles.atlas.vegvesen.no/vegnett/api/v4/";
$querystr = "posisjon?{$latlon}&maks_avstand=20&maks_antall=1&konnekteringslenker=true&detaljerte_lenker=true&srid=WGS84&trafikantgruppe=K";
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url . $querystr);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// grab URL and pass it to the browser
curl_exec($ch);
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
// echo 'Operation completed without any errors';
$response = curl_exec($ch);
// Decoding JSON data
$decodedData = json_decode($response, true);
// Outputting JSON data in
// Decoded form
//echo $ch;
//echo $response;
echo "$lat, $lon";
echo "<br><br>Kortform:";
echo $decodedData[0]['vegsystemreferanse']['kortform'];
echo "<br><br>Raw data";
echo '<pre>';
print_r($decodedData);
echo '<br><br>';
}
?>

44
index.php Normal file
View File

@@ -0,0 +1,44 @@
<html>
<head>
<title>Test av alt</title>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showLocation);
}else{
$('#location').html('Geolocation is not supported by this browser.');
}
});
function showLocation(position){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
$.ajax({
type:'POST',
url:'getLocation.php',
data:'latitude='+latitude+'&longitude='+longitude,
success:function(msg){
if(msg){
$("#location").html(msg);
}else{
$("#location").html('Not Available');
}
}
});
}
</script>
<body>
<p>Your Location: <span id="location"></span></p>
<p>Lat: <span id="lat"></span></p>
<p>Lon: <span id="lon"></span></p>
<?php
echo $latlon;
?>
</body>
</html>