Rudimentary smart box on the landing page
This commit is contained in:
parent
d72e9eb10b
commit
fa44970fd1
9
app.py
9
app.py
|
@ -30,6 +30,15 @@ def showMap(threewords):
|
|||
return template('index',
|
||||
err="Could not find location {}".format(threewords))
|
||||
|
||||
@get('/latlng/<lat:float>,<lng:float>')
|
||||
def showMapFromLatLng(lat, lng):
|
||||
try:
|
||||
threewords = these.three_words((lat, lng))
|
||||
return template('map', lat=lat, lng=lng, threewords=threewords)
|
||||
except:
|
||||
return template('index',
|
||||
err="Could not find location {}".format(threewords))
|
||||
|
||||
|
||||
# API
|
||||
@get('/api/<lat:float>,<lng:float>')
|
||||
|
|
|
@ -8,8 +8,33 @@
|
|||
<!-- Style -->
|
||||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="/static/css/style.css">
|
||||
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
|
||||
<script>
|
||||
function initialize() {
|
||||
// Create the autocomplete object, restricting the search
|
||||
// to geographical location types.
|
||||
var searchbox = new google.maps.places.SearchBox(
|
||||
(document.getElementById('input3words')));
|
||||
// When the user selects an address from the dropdown,
|
||||
// populate the address fields in the form.
|
||||
google.maps.event.addListener(searchbox, 'places_changed', function() {
|
||||
// Get the place details from the autocomplete object.
|
||||
var places = searchbox.getPlaces();
|
||||
|
||||
if (places.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
place = places[0];
|
||||
lat = place.geometry.location.lat();
|
||||
lng = place.geometry.location.lng();
|
||||
window.location = '/latlng/' + lat +","+lng;
|
||||
console.log("lat:" + lat + " lng:" + lng);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<body onload="initialize()">
|
||||
<div class="container">
|
||||
% if err:
|
||||
<aside class="alert alert-danger" role="alert">Error: {{ err }}</aside>
|
||||
|
@ -30,7 +55,7 @@
|
|||
<footer>
|
||||
<p class="text-center text-muted">Made with ♥ by <a href="https://betatim.github.io/">Tim</a> and <a href="https://dun.gs">Kevin</a>. <a href="https://github.com/betatim/these-3-words">Fork it on GitHub</a>.
|
||||
</footer>
|
||||
<script>
|
||||
<!--<script>
|
||||
(function() {
|
||||
var default3words = 'spitting-ripple-fontanel';
|
||||
var threewordsField = document.getElementById('input3words');
|
||||
|
@ -46,7 +71,7 @@
|
|||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</script> -->
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue