Get Latitude/longitude Button To Fill Input Boxes
I have two text boxes that I want users to fill with geolocation data (latitude and longitude). I want to have a button, so when users click it, the text boxes are filled instantly
Solution 1:
You are not really saying what the problem is, but as far as I know innerHTML only works in FF and not IE. Try:
functionshowPosition(position) {
x.value=position.coords.latitude;
y.value=position.coords.longitude;
}
Working example as requested in the comments
<!DOCTYPE html><html><body><form>
Latitude: <inputid="demo"type="text"name="Latitude" /><br />
Longitude: <inputid="demo2"type="text"name="Longitude" /></form><buttononclick="getLocation()">Get Location</button><inputtype="submit"value="Submit" /><p>Click the button to get your coordinates:</p><pid="demo2">Click the button to get your coordinates:</p><script>var x=document.getElementById("demo");
var y=document.getElementById("demo2");
functiongetLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}
functionshowPosition(position)
{
x.value=position.coords.latitude;
y.value=position.coords.longitude;
}
</script></body></html>
Post a Comment for "Get Latitude/longitude Button To Fill Input Boxes"