0
Follows the code____________________________________
<!DOCTYPE html>
<html>
<body>
<p>Click the button to get your coordinates.</p>
<button onclick="getLocation()">Map On</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Localizacao: " + position.coords.latitude+","+ position.coords.longitude;
}
</script>
<?php
$teste = "<script>getLocation()</script>";
echo $teste;
$latAqui = explode(" ", $teste);
print_r($latAqui);
?>
Retorno até o presente momento_______________________________________
Localizacao: -22.3588937,-47.3859919
Array ( [0] => )
Could you give an example or a website for me to see, please?
– Julio Ramos
@Julioramos complemented the answer. Understand that it is not a trivial process. You can’t put the complete code of the project here because you have to tinker with several tips, but it’s the only way to do this check. Without relying on browser integration only if done by IP. But you will need to consult an external service or buy a geolocated IP base.
– Leandro Oriente
By ip is not possible, it returns ips from the region, because ip is dynamic.
– Julio Ramos
The IP base takes the region prefix. It is usually accurate at city level. Even though the user has a dynamic IP, they can get it right because it picks up the location prefix. Using the browser’s geolocation API only passing through AJAX itself. You can pass data from PHP to the browser directly on the page, but you can never get past Javascript pro PHP without another connection like AJAX and Websockets for example.
– Leandro Oriente