var alr = document.getElementById("alert");
var par = document.getElementById("paragraph");
var pos = document.getElementById("position");
var str = document.getElementById("street");
var nei = document.getElementById("neighborhood");
var cit = document.getElementById("city");
var sta = document.getElementById("state");
var zip = document.getElementById("zip");
function getLocation() {
try
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(getInfo);
}
else
{
alr.innerHTML = "Geolocation is not supported by this browser.";
}
}
catch(e)
{
alr.innerHTML = "Geolocation is not supported by this browser.";
}
}
//Shows the position numbers
function showPosition(lat,long)
{
pos.innerHTML = "Latitude: " + lat +
"<br>Longitude: " + long;
}
//Show the address in a paragraph
function showComplete(data)
{
par.textContent = "You are in "+data.results[0].address_components[1].long_name+", "+data.results[0].address_components[2].long_name+", "+data.results[0].address_components[4].long_name+", "+data.results[0].address_components[5].short_name+", Postal Code: "+data.results[0].address_components[7].short_name+".";
}
//Fills out the form
function fillForm(data)
{
str.value = data.results[0].address_components[1].long_name;
nei.value = data.results[0].address_components[2].long_name;
cit.value = data.results[0].address_components[4].long_name;
sta.value = data.results[0].address_components[5].short_name;
zip.value = data.results[0].address_components[7].short_name;
}
function getInfo(position)
{
latlng = position.coords.latitude+","+position.coords.longitude;
request = new XMLHttpRequest();
request.open('GET', 'http://maps.googleapis.com/maps/api/geocode/json?latlng='+latlng, true);
request.onload = function()
{
if (request.status == 200 || request.status == 0 )
{
// Success!
data = JSON.parse(request.responseText);
//Call the method...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.