Forum Moderators: open
<!DOCTYPE html />
<html>
<head>
<title>User's current detection'</title>
<link href='http://fonts.googleapis.com/css?family=Terminal+Dosis:800,600' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="css/styles1.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder = new google.maps.Geocoder();
function initialize() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(foundYou, notFound);
} else {
alert('Geolocation not supported or not enabled.');
}
}
function notFound(msg) {
alert('Could not find your location :(')
}
function foundYou(position) {
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
geocoder.geocode({'latLng': latlng}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
var address = results[0].address_components[1].long_name+' '+results[0].address_components[0].long_name+', '+results[0].address_components[3].long_name
$('.autoLink span').html(address).parent().show().click(function()
{}
);
}
} else {
alert("Geocoder failed due to: " + status);
}
}
);
}
</script>
</head>
<body onLoad="initialize()">
<h1>Current position detection</h1>
<div style="width: 500px; float: left; text-align: left; margin-right: 40px">
<a href="#" class="autoLink">Use current location: <span>not found</span></a>
</div><!-- .wrapper -->
</body>
</html>