名前、経度、緯度のテキスト フィールドを含む HTML フォームがあります。経度と緯度は JavaScript 変数に格納されます。名前、緯度、経度をサーバーに投稿する方法を知っていますか?つまり、URLを介してですか? フォームを送信するたびに、経度と緯度が URL に渡されませんか? 誰でもその方法を教えてもらえますか?
ありがとうございました
これは私のjavascriptとhtmlの両方の私のコードです:
if (navigator.geolocation) {
var geolocation = {};
geolocation.latitude = 0;
geolocation.longitude = 0;
navigator.geolocation.getCurrentPosition(function (p) {
geolocation.latitude = p.coords.latitude;
geolocation.longitude = p.coords.longitude;
}, function (error) {
alert("Failed to get GPS location");
});
} else {
alert("Failed to get GPS working");
}
function loc() {
document.getElementById("longitude").value = geolocation.latitude;
document.getElementById("latitude").value = geolocation.longitude;
}
html:
<form name="photo" method="post" action="url">
<label for="name">Name:</label>
<input type="text" name="name" id="Text1" value="" />
<label for="longitude">Longitude:</label>
<input type="text" name="longitude" id="longitude" />
<label for="latitude">Latitude:</label>
<input type="text" name="latitude" id="latitude" />
<label for="image">Image:</label>
<input type="text" name="image" id="image" />
<input type="submit" value="Submit" />
</form>