Skip to content

Commit

Permalink
show distance on close locations
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Wainstock committed Oct 13, 2015
1 parent 15e3e6f commit 976e48b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions app/assets/javascripts/application.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ function switchSection(newSection) {
$("#" + newSection + "_section_link").toggleClass("active_section_link");
}

function initSearch(region, locationIDs, locationTypeIDs, zoneIDs, machineIDs, ipdbIDs, cityName, machineGroupId) {
function initSearch(region, locationIDs, locationTypeIDs, zoneIDs, machineIDs, ipdbIDs, cityName, machineGroupId, showLocationDistance, lat, lon) {
if (locationIDs || locationTypeIDs || zoneIDs || machineIDs || ipdbIDs || cityName || machineGroupId) {
var url = '/' + region + '/locations?by_location_id=' + locationIDs + ';by_type_id=' + locationTypeIDs + ';by_zone_id=' + zoneIDs + ';by_machine_id=' + machineIDs + ';by_city_id=' + cityName + ';by_machine_group_id=' + machineGroupId + ';by_ipdb_id=' + ipdbIDs;
var url = '/' + region + '/locations?by_location_id=' + locationIDs + ';by_type_id=' + locationTypeIDs + ';by_zone_id=' + zoneIDs + ';by_machine_id=' + machineIDs + ';by_city_id=' + cityName + ';by_machine_group_id=' + machineGroupId + ';by_ipdb_id=' + ipdbIDs + ';show_location_distance=' + showLocationDistance + ';lat=' + lat + ';lon=' + lon;

$('#locations').html(loadingHTML());
$.get(url, function(data) {
Expand All @@ -116,18 +116,18 @@ function initSearch(region, locationIDs, locationTypeIDs, zoneIDs, machineIDs, i

function findClosestLocations(region) {
navigator.geolocation.getCurrentPosition(function(position) {
var dfd = $.getJSON('/api/v1/locations/closest_by_lat_lon.json', {lat: position.coords.latitude, lon: position.coords.longitude, max_distance: 20, send_all_within_distance: 1});
var dfd = $.getJSON('/api/v1/locations/closest_by_lat_lon.json', {lat: position.coords.latitude, lon: position.coords.longitude, max_distance: 5, send_all_within_distance: 1});
dfd.done(function(response) {
if (!response.locations) {
document.getElementById("map_canvas").innerHTML="<p id='intro' class='dark hello'>" + "Sorry, there are no locations within 20 miles of you." + "</p>";
document.getElementById("map_canvas").innerHTML="<p id='intro' class='dark hello'>" + "No pinball found on this map within 5 miles of your location." + "</p>";
} else {
var locationIds = [];

for (var i = 0; i < response.locations.length; i++) {
locationIds.push(response.locations[i].id)
}

window.location.href = 'http://pinballmap.com/'+ region + '/?by_location_id=' + locationIds.join('_');
window.location.href = 'http://pinballmap.com/'+ region + '/?show_location_distance=1;lat=' + position.coords.latitude + ';lon=' + position.coords.longitude + ';by_location_id=' + locationIds.join('_');
}
});
}, function() {
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
= favicon_link_tag 'favicon.ico'
= favicon_link_tag 'apple-touch-icon.png', rel: 'apple-touch-icon', type: 'image/png'

%body{ :onload => defined?(@region) ? "setSearchSections(#{@region.available_search_sections}); switchSection('#{(@region.default_search_type && !@region.default_search_type.empty?) ? @region.default_search_type : 'location'}'); initSearch('#{@region.name.downcase}', '#{params['by_location_id']}', '#{params['by_location_type_id']}', '#{params['by_zone_id']}', '#{params['by_machine_id']}','#{params['by_ipdb_id']}','#{params['by_city_id']}', '#{params['by_machine_group_id']}');" : nil }
%body{ :onload => defined?(@region) ? "setSearchSections(#{@region.available_search_sections}); switchSection('#{(@region.default_search_type && !@region.default_search_type.empty?) ? @region.default_search_type : 'location'}'); initSearch('#{@region.name.downcase}', '#{params['by_location_id']}', '#{params['by_location_type_id']}', '#{params['by_zone_id']}', '#{params['by_machine_id']}','#{params['by_ipdb_id']}','#{params['by_city_id']}', '#{params['by_machine_group_id']}', '#{params['show_location_distance']}', '#{params['lat']}', '#{params['lon']}');" : nil }
#container
#page
= render :partial => 'pages/header'
Expand Down
2 changes: 2 additions & 0 deletions app/views/locations/_locations.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
%div.sub_nav_location[l, :show_location_detail]{:onclick => "showLocationDetail(#{l.id});"}
%ul
%li.name= l.name
- if (!params[:show_location_distance].blank? && !params[:lat].blank? && !params[:lon].blank?)
%li.location_type= " distance: #{l.distance_from([params[:lat], params[:lon]]).round(2)} miles"
- if (l.location_type)
%li.location_type= " (#{l.location_type.name})"
.clear
Expand Down

0 comments on commit 976e48b

Please sign in to comment.