Skip to content

Instantly share code, notes, and snippets.

@s0ren
Created March 7, 2017 08:04
Show Gist options
  • Save s0ren/f1116c423d283fd7a3089db3a1e99e7a to your computer and use it in GitHub Desktop.
Save s0ren/f1116c423d283fd7a3089db3a1e99e7a to your computer and use it in GitHub Desktop.
Peopos js demo
<!DOCTYPE html>
<html>
<head>
<title>Geolocation</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<meta http-equiv="Content-Security-Policy"
content="default-src * gap: ws: https://ssl.gstatic.com https://maps.googleapis.com;
img-src * 'self' https://maps.googleapis.com data: content:;
style-src 'self' 'unsafe-inline' data: blob:;
script-src * 'unsafe-inline' 'unsafe-eval' https://maps.googleapis.com data: blob:;">
</head>
<body>
<div id="map"></div>
<script>
// Note: This example requires that you consent to location sharing when
// prompted by your browser. If you see the error "The Geolocation service
// failed.", it means you probably did not give permission for the browser to
// locate you.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 6
});
var infoWindow = new google.maps.InfoWindow({map: map});
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
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=AIzaSyDJcPdRHeUKW67sxwBdMi3mIElqb87fUns&callback=initMap">
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment