Get elevation with leaflet.js
Leaflet.js is a powerful web tool based on GIS (Geographic Information Systems). The following shows how a user, after clicking on a certain location, will obtain the elevation of the terrain, all thanks to the api free of https://open-elevation.com/

Click on any point on the map to get the elevation
Example code (Javascript)
       // Initialize the map
        var map = L.map('map').setView([0, 0], 2);

        // Add OpenStreetMap tiles
        L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            maxZoom: 18,
            attribution: '© OpenStreetMap contributors'
        }).addTo(map);

        // Función para manejar clics en el mapa
        function onMapClick(e) {

            const form_data = new FormData();
            form_data.append('lat', e.latlng.lat);
            form_data.append('lng', e.latlng.lng);
            fetch("ajax.php", {
                method: "POST",
                body: form_data
            }).then(function(response) {
                return response.json();
            }).then(function(data) {
                if (!data.success) return;
                const json = JSON.parse(data.json);
                const elevation = json.results[0].elevation;

                L.popup()
                    .setLatLng([lat, lng])
                    .setContent('Elevation: ' + elevation + ' meters')
                    .openOn(map);
                
            });

            // Obtener las coordenadas clickeadas
            var lat = e.latlng.lat;
            var lng = e.latlng.lng;
        };

        // Añadir el listener de clics en el mapa
        map.on('click', onMapClick);
            
            
Handling the request with PHP (ajax.php)
$response = new stdClass();
$response->success = false;
$response->json = null;
$response->lat = filter_input(INPUT_POST, 'lat');
$response->lng = filter_input(INPUT_POST, 'lng');

$response->url = "https://api.open-elevation.com/api/v1/lookup?locations=". $response->lat . "," . $response->lng; 

$json = file_get_contents($response->url);

if ($json) {
    
    $response->json = $json;
    $response->success = true;
    
}

echo json_encode($response);


Comentar:
captcha

Comentarios: Sin comentarios

Below you can find the necessary commands to carry out a correct installation of PyQt6...

Seguir leyendo...

Proper indentation makes HTML code easier to read and understand. When HTML tags are well organized and nested correctly, it is easier for developers to identify the structure of the document, see which elements contain others, and understand the hierarchy of ...

Seguir leyendo...

Indenting JavaScript code not only improves the aesthetics of the code, but also offers significant practical benefits that make it easier to read, maintain, collaborate, and overall quality of the software. It's an essential practice for any developer looking...

Seguir leyendo...

Below is an example of how to obtain weather data with Leaflet.js and the free Open-Meteo api....

Seguir leyendo...

Well-formatted code provides a clear visual guide to how styles are applied and how rules are grouped. Well-indented CSS code is easier to maintain. When the code is organized, it is easier to make changes and updates without introducing errors. Indentation he...

Seguir leyendo...

For machine translation tasks, models based on the Transformer architecture have proven to be very effective....

Seguir leyendo...

The audio element in HTML is a powerful tool for integrating sound content into web pages....

Seguir leyendo...

The video element is one of the most prominent features of HTML5, as it allows developers to embed videos directly into web pages....

Seguir leyendo...

Discover the essential steps to upload your applications to Play Store and be a successful developer....

Seguir leyendo...

(GIS) on the web have revolutionized the way we interact with spatial data, below are the most important JS libraries....

Seguir leyendo...

The following article shows a basic example of how to activate the camera and audio with Javascript....

Seguir leyendo...

Explore the advantages of Kotlin over Java in Android application development....

Seguir leyendo...