Muito obrigado, Toledo.
No teu site funcionou perfeitamente.
No meu também. Fiz a adaptação do HTPP, e ficou ok.
Mas agora estou tentando inserir este script na função que estou fazendo, e daÃ, não sei porque, não está funcionando.
Sei que devo ter feito algo errado, pois não sei bem como inseri-lo dentro da minha função.
Veja como estou fazendo. O primeiro arquivo ficou assim:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Controle do carro</title>
<body>
<form id="carro" name="carro" method="post" action="cadcarro.php" onsubmit="return validaCampo(); return false;">
<table width="625" border="0">
<br>
<br>
Favor preencher os dados abaixo:
<br>
<br>
<tr>
<td width="89">Quilometragem atual:</td>
<td width="546"><input name="km" type="text" id="km" size="10" maxlength="10" />
<span class="style1"></span></td>
</tr>
<tr>
<td width="69">Local do cadastro:</td>
<td width="546"><input name="local" type="text" id="local" size="20" maxlength="20" />
<span class="style1"></span></td>
</tr>
<br>
<br>
<tr>
<td colspan="4"><p>
<button onclick="getLocation()">Cadastrar dados</button>
<p id="demo"></p>
<input name="limpar" type="reset" id="limpar" value="Limpar Campos preenchidos" />
<span class="style1"> </span></p>
<p> </p></td>
</tr>
</table>
</form>
</body>
</html>
<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) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
var url_php = "http://www.inaciocarvalho.com.br/php/cadcarro.php?lat="+lat+"&lon="+lon;
location.href= url_php;
}
</script>
</body>
</html>
O segundo, ainda não terminado, está assim:
<html>
<head>
</head>
<body>
<?php
$km = $_POST['km'];
$lc = $_POST['local'];
$hr = (date('H')).":".date('i').":".date('s');
$dt = date('Y')."-".date('m')."-".date('d');
$lat = ( isset($_POST['lat']) ) ? $_POST['lat'] : $_GET['lat'];
$lon = ( isset($_POST['lon']) ) ? $_POST['lon'] : $_GET['lon'];
echo "<font face='arial' color='orange' size='50'>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "Km: ".$km;
echo "<br>";
echo "<br>";
echo "Local: ".$lc;
echo "<br>";
echo "<br>";
echo "Latitude: ".$lat;
echo "<br>";
echo "<br>";
echo "Longitude: ".$lon;
echo "<br>";
echo "<br>";
echo "<br>";
echo '<form action="carro.php"';
echo "width='65%' style='height:150px;'>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<input size='35' style='font-size:120px' type='submit' id='Voltar' value='Voltar'>";
echo "</form>";
?>
Neste caso, as variáveis $lon e $lat estão em branco.