Geolocation
HTML
<section class="card endpoint" id="get_users_self">
<header>
<h2>
<span class="ep-type">HQ</span>
<code>Cincinnat, Ohio</code>
</h2>
</header>
<div class="card-info">
<select class="actions" id="location-selector">
<option id="1" value="first-location">Location 1</option>
<option id="2" value="second-location">Location 2</option>
<option id="3" value="third-location">Location 3</option>
<option id="4" value="fourth-location">Location 4</option>
</select>
Please plot 4 locations on the map below to make a border around the property you'd like to enforce geo-fencing.
</div>
<div class="card-description ep-description"></div>
<table>
<caption><strong>Parameters</strong><i></i></caption>
<tbody>
<tr>
<th>Location 1 (LAT, LONG)</th>
<td class="first-location-lat">Please plot a point.</td>
<td class="first-location-long">Please plot a point.</td>
</tr>
<tr>
<th>Location 2 (LAT, LONG)</th>
<td class="second-location-lat">Please plot a point.</td>
<td class="second-location-long">Please plot a point.</td>
</tr>
<tr>
<th>Location 3 (LAT, LONG)</th>
<td class="third-location-lat">Please plot a point.</td>
<td class="third-location-long">Please plot a point.</td>
</tr>
<tr>
<th>Location 4 (LAT, LONG)</th>
<td class="fourth-location-lat">Please plot a point.</td>
<td class="fourth-location-long">Please plot a point.</td>
</tr>
</tbody>
</table>
</div>
</section>
<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap">
</script>
<!-- -->
CSS
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
/* This file was auto - @generated by running bin/yolo sass */
/* (c) 2012 Instagram, Inc, */
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
nav,
section {
display: block;
}
audio,
canvas,
video {
display: inline-block;
*display: inline;
*zoom: 1;
}
audio:not([controls]) {
display: none;
}
[hidden] {
display: none;
}
html {
font-size: 100%;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
html,
button,
input,
select,
textarea {
font-family: sans-serif;
}
body {
margin: 0;
}
h1 {
font-size: 2em;
}
abbr[title] {
border-bottom: 1px dotted;
}
b,
strong {
font-weight: bold;
}
blockquote {
margin: 1em 40px;
}
dfn {
font-style: italic;
}
mark {
background: #ff0;
color: #000;
}
pre,
code,
kbd,
samp {
font-family: monospace, serif;
_font-family: 'courier new', monospace;
font-size: 1em;
}
pre {
white-space: pre;
white-space: pre-wrap;
word-wrap: break-word;
}
q {
quotes: none;
}
q:before,
q:after {
content: '';
content: none;
}
small {
font-size: 75%;
}
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sup {
top: -0.5em;
}
sub {
bottom: -0.25em;
}
ul,
ol {
margin-left: 0;
padding: 0 0 0 40px;
}
dd {
margin: 0 0 0 40px;
}
nav ul,
nav ol {
list-style: none;
list-style-image: none;
}
img {
border: 0;
-ms-interpolation-mode: bicubic;
}
svg:not(:root) {
overflow: hidden;
}
figure {
margin: 0;
}
form {
margin: 0;
}
fieldset {
border: 1px solid #c0c0c0;
margin: 0 2px;
padding: 0.35em 0.625em 0.75em;
}
legend {
border: 0;
padding: 0;
white-space: normal;
*margin-left: -7px;
}
button,
input,
select,
textarea {
font-size: 100%;
margin: 0;
vertical-align: baseline;
*vertical-align: middle;
}
button,
input {
line-height:...
JavaScript
// 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
});
google.maps.event.addListener(map, 'click', function(event) {
var opt = $("#location-selector").val();
var lat = $("." + opt + "-lat").html(event.latLng.lat());
var long = $("." + opt + "-long").html(event.latLng.lng());
var locationId = $("#location-selector option:selected").prop("id");
var marker = new google.maps.Marker({
position: {
lat: event.latLng.lat(),
lng: event.latLng.lng()
},
map: map,
label: locationId
});
});
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.');
}