Ich habe hier einen Code, der den aktuellen Standort des Benutzers anzeigt, dieser Code funktioniert bereits. Mein Problem ist, wie man die ID "#location" als den Wert für meine Textbox in HTML-Formular setzt, so dass der aktuelle Standort in ein Textfeldformular eingefügt wird.Anzeige der aktuellen Position des Benutzers als Wert der Textbox
$(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:'../geo/getLocation.php',
data:'latitude='+latitude+'&longitude='+longitude,
success:function(msg){
if(msg){
$("#location").html(msg);
}else{
$("#location").html('Not Available');
}
}
});
}
HTML:
Location: <input id="location" type="text" value="" size="50">
<br>
Was ist das Problem? Was gibt Ihre Ajax-Anfrage als Antwort zurück? Hast du überhaupt debuggen? – trincot
Mein Code funktioniert bereits. Er zeigt den aktuellen Standort des Benutzers an. Mein Problem ist, wie man den id #location als ein Wert für mein html-Textboxformular setzt, so dass der gegenwärtige Standort zum Textboxformular geht. –
Warum haben Sie meine Korrektur Ihrer Frage rückgängig gemacht? Glaubst du wirklich "ein Code" ist richtig Englisch !? – trincot