-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an around bus stop search using HTML5 geolocation API
- Loading branch information
1 parent
146e8a1
commit ebcad9a
Showing
9 changed files
with
41 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ | ||
$ -> | ||
$("input[data-geolocation]").click (e) -> | ||
return if ($('#q').val() != '') # keyword search | ||
if (navigator.geolocation) | ||
navigator.geolocation.getCurrentPosition(success, error) | ||
else | ||
console.warn('Navigator.geolocation not supported.') | ||
false | ||
|
||
success = (position) -> | ||
lat = position.coords.latitude | ||
long = position.coords.longitude | ||
window.location.href = '/bus_stops/?position=' + lat + ',' + long | ||
|
||
error = (err) -> | ||
console.warn('ERROR(' + err.code + '): ' + err.message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<%= form_tag bus_stops_path, :method => 'get' do %> | ||
<div class="input-group"> | ||
<%= text_field_tag :q, params[:q] || session[:q], placeholder: 'バス停名を省略すると周辺を検索します。', class: 'form-control' %> | ||
<span class="input-group-btn"> | ||
<%= submit_tag '検索', name: nil, class: 'btn btn-primary', data: { geolocation: '' } %> | ||
</span> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters