-
-
Save bharris62/707435d275f0c18c130d6b7ae057fb1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Geolocation</title> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"> | |
<meta charset="utf-8"> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | |
<!-- Optional theme --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> | |
<!-- Latest compiled and minified JavaScript --> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> | |
<style> | |
/* Always set the map height explicitly to define the size of the div | |
* element that contains the map. */ | |
#map { | |
height: 60%; | |
} | |
/* Optional: Makes the sample page fill the window. */ | |
html, body { | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script> | |
function initMap() { | |
var map = new google.maps.Map(document.getElementById('map'), { | |
center: {lat: 36.162664, lng: -86.781602}, | |
zoom: 15 | |
}); | |
var infoWindow = new google.maps.InfoWindow({map: map}); | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition(function(position) { | |
var pos = { | |
lat: position.coords.latitude, | |
lng: position.coords.longitude | |
}; | |
var marker = new google.maps.Marker({ | |
position: pos, | |
map: map, | |
draggable: true, | |
title: 'Learn More' | |
}); | |
marker.addListener('click', function() { | |
infowindow.open(map, marker); | |
}); | |
var contentString = '<div class="row">' + | |
'<div class="col-sm-12">' + | |
'<div class="thumbnail">' + | |
'<img src="http://placehold.it/192x200">' + | |
'<div class="caption">' + | |
'<h3>Thumbnail label</h3>' + | |
'<p>Attack the dog then pretend like nothing happened</p>' + | |
'<p>claw drapes hide from vacuum cleaner but pose purrfectly to show my beauty.</p>' + | |
'<p>Tuxedo cats always looking dapper unwrap toilet paper.</p><br>' + | |
'<p><a href="#" class="btn btn-success" role="button">Accept</a> <a href="#" class="btn btn-danger" role="button">Reject</a></p>' + | |
'</div>' + | |
'</div>' + | |
'</div>' + | |
'</div>'; | |
var infowindow = new google.maps.InfoWindow({ | |
content: contentString | |
}); | |
map.setCenter(pos); | |
}, function() { | |
handleLocationError(true, infoWindow, map.getCenter()); | |
}); | |
} else { | |
handleLocationError(false, infoWindow, map.getCenter()); | |
} | |
} | |
function handleLocationError(browserHasGeolocation, infoWindow, pos) { | |
infoWindow.setPosition(pos); | |
infoWindow.setContent(browserHasGeolocation ? | |
'Error: The Geolocation service failed.' : | |
'Error: Your browser doesn\'t support geolocation.'); | |
} | |
</script> | |
<script async defer | |
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDoKoDr3vBROrz5WuUfyak1S8CdCh08F1w&callback=initMap"> | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment