Skip to content

Instantly share code, notes, and snippets.

@nch7
Created May 14, 2016 21:36
Show Gist options
  • Save nch7/83dc40df5409410bc5aefed412b57d8d to your computer and use it in GitHub Desktop.
Save nch7/83dc40df5409410bc5aefed412b57d8d to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Geolocation</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = null;
function addMarker(location) {
console.log("setting marker on ", location);
var marker = new google.maps.Marker({
position: location,
label: "",
map: map
});
}
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 14
});
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
map.setCenter(pos);
search(["quia", "mollitia", "nobis"]);
});
}
}
function search(tags) {
$.ajax({
url: '/api/v1/guest/search',
data: {
tags: tags,
locx: map.getCenter().lat(),
locy: map.getCenter().lng(),
radius: 50
}
}).success(function(response) {
for(var i in response) {
addMarker({"lat":parseFloat(response[i].locx),"lng":parseFloat(response[i].locy)});
}
});
}
</script>
<script src="https://code.jquery.com/jquery-1.12.3.min.js" integrity="sha256-aaODHAgvwQW1bFOGXMeX+pC4PZIPsvn2h1sArYOhgXQ=" crossorigin="anonymous"></script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBVlsbuHorPmE0otpgBhEtFs847MQwJtN4&callback=initMap"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment