I'm attempting to use TheNewBoston's video to code a site that has a "Get Location" button and will pull up a Google map of the user's location. However, every time I click 'Get Location' on my site, nothing happens. I was playing around with the code and was able to get a map to show up once, but I'm unable to get that result again and have no idea how I got it to work. Not sure what I'm doing wrong?
Here's my code:
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Location Retriever</title>
</head>
<body>
<a href="#" id="get_location">Get Location</a>
<div> id="map">
<iframe id="google_map" width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com">
</div>
<script>
var c = function(pos) {
var lat = pos.coords.latitude,
var long = pos.coords.longitude,
var coords = lat + ', ' + long;
document.getElementById('google_map').setAttribute('src','https://maps.google.com' + coords + '&z=60&output=embed');
}
document.getElementById('get_location').onclick = function() {
navigator.geolocation.getCurrentPosition(c);
return false;
}
</script>