Skip to content

Commit

Permalink
Fall back to positon lookup based on IP number (#261)
Browse files Browse the repository at this point in the history
If browser geolocation API returned no position
  • Loading branch information
fsteeg committed Sep 7, 2016
1 parent 5184d4f commit dbcd49d
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,37 @@
<script src='@controllers.routes.Assets.at("javascripts/bootstrap.min.js")'></script>
@scripts
<script>
function postPosition(lat, lon) {
var url = '/organisations/position?lat=' + lat + '&lon=' + lon;
$.ajax({
url: url,
type: 'POST',
success: function(data, textStatus, jqXHR) {
console.log('Server response: ' + data);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus + ": " + errorThrown);
}
});
}
window.onload = function() {
var options = {
maximumAge: 5 * 60 * 1000,
timeout: 10 * 1000
}
var success = function(position) {
console.log(position);
var url = '/organisations/position?lat=' + position.coords.latitude + '&lon=' + position.coords.longitude;
$.ajax({
url: url,
type: 'POST',
success: function(data, textStatus, jqXHR) {
console.log('Server response: ' + data);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus + ": " + errorThrown);
}
});
postPosition(position.coords.latitude, position.coords.longitude);
};
var error = function(error) {
console.log(error);
console.log('Attempting fallback lookup based on IP number');
var latLong;
$.getJSON("http://ipinfo.io", function(response) {
console.log("Found position: " + response.loc);
var latLon = response.loc.split(",");
postPosition(latLon[0], latLon[1]);
});
};
@if(play.mvc.Controller.session("position") == null) {
if (navigator.geolocation) {
Expand Down

0 comments on commit dbcd49d

Please sign in to comment.