Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ability save and show point on the google map
- Loading branch information
Showing
22 changed files
with
429 additions
and
1 deletion.
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
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,3 @@ | ||
# 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://jashkenas.github.com/coffee-script/ |
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,3 @@ | ||
// Place all the styles related to the checkins controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
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,56 @@ | ||
body { | ||
background-color: #fff; | ||
color: #333; | ||
font-family: verdana, arial, helvetica, sans-serif; | ||
font-size: 13px; | ||
line-height: 18px; } | ||
|
||
p, ol, ul, td { | ||
font-family: verdana, arial, helvetica, sans-serif; | ||
font-size: 13px; | ||
line-height: 18px; } | ||
|
||
pre { | ||
background-color: #eee; | ||
padding: 10px; | ||
font-size: 11px; } | ||
|
||
a { | ||
color: #000; | ||
&:visited { | ||
color: #666; } | ||
&:hover { | ||
color: #fff; | ||
background-color: #000; } } | ||
|
||
div { | ||
&.field, &.actions { | ||
margin-bottom: 10px; } } | ||
|
||
#notice { | ||
color: green; } | ||
|
||
.field_with_errors { | ||
padding: 2px; | ||
background-color: red; | ||
display: table; } | ||
|
||
#error_explanation { | ||
width: 450px; | ||
border: 2px solid red; | ||
padding: 7px; | ||
padding-bottom: 0; | ||
margin-bottom: 20px; | ||
background-color: #f0f0f0; | ||
h2 { | ||
text-align: left; | ||
font-weight: bold; | ||
padding: 5px 5px 5px 15px; | ||
font-size: 12px; | ||
margin: -7px; | ||
margin-bottom: 0px; | ||
background-color: #c00; | ||
color: #fff; } | ||
ul li { | ||
font-size: 12px; | ||
list-style: square; } } |
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,90 @@ | ||
class CheckinsController < ApplicationController | ||
# GET /checkins | ||
# GET /checkins.json | ||
def index | ||
@checkins = Checkin.all | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.json { render json: @checkins } | ||
end | ||
end | ||
|
||
# GET /checkins/1 | ||
# GET /checkins/1.json | ||
def show | ||
@checkin = Checkin.find(params[:id]) | ||
|
||
@nearby_checkins = Checkin.nearby_to(@checkin, 1000) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.json { render json: @checkin } | ||
end | ||
end | ||
|
||
# GET /checkins/new | ||
# GET /checkins/new.json | ||
def new | ||
@checkin = Checkin.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.json { render json: @checkin } | ||
end | ||
end | ||
|
||
# GET /checkins/1/edit | ||
def edit | ||
@checkin = Checkin.find(params[:id]) | ||
end | ||
|
||
# POST /checkins | ||
# POST /checkins.json | ||
def create | ||
@checkin = Checkin.new(params[:checkin]) | ||
|
||
if @checkin.valid? | ||
puts '---controller' | ||
puts @checkin.inspect | ||
end | ||
|
||
respond_to do |format| | ||
if @checkin.save | ||
format.html { redirect_to @checkin, notice: 'Checkin was successfully created.' } | ||
format.json { render json: @checkin, status: :created, location: @checkin } | ||
else | ||
format.html { render action: "new" } | ||
format.json { render json: @checkin.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /checkins/1 | ||
# PUT /checkins/1.json | ||
def update | ||
@checkin = Checkin.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @checkin.update_attributes(params[:checkin]) | ||
format.html { redirect_to @checkin, notice: 'Checkin was successfully updated.' } | ||
format.json { head :no_content } | ||
else | ||
format.html { render action: "edit" } | ||
format.json { render json: @checkin.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /checkins/1 | ||
# DELETE /checkins/1.json | ||
def destroy | ||
@checkin = Checkin.find(params[:id]) | ||
@checkin.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to checkins_url } | ||
format.json { head :no_content } | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module CheckinsHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Checkin < ActiveRecord::Base | ||
attr_accessible :location, :title, :latitude, :longitude | ||
|
||
scope :nearby_to, | ||
lambda { |checkin, max_distance| | ||
where("ST_DWithin(location, ?, ?) AND id != ?", checkin.location, max_distance, checkin.id) | ||
} | ||
|
||
def latitude | ||
self.location.nil? ? 0 : self.location.y | ||
end | ||
|
||
def latitude=(value) | ||
self.location = "POINT(#{longitude} #{value})" | ||
end | ||
|
||
def longitude | ||
self.location.nil? ? 0 : self.location.x | ||
end | ||
|
||
def longitude=(value) | ||
self.location = "POINT(#{value} #{latitude})" | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<%= form_for(@checkin) do |f| %> | ||
<% if @checkin.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@checkin.errors.count, "error") %> prohibited this checkin from being saved:</h2> | ||
|
||
<ul> | ||
<% @checkin.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= f.label :title %> | ||
<br/> | ||
<%= f.text_field :title %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :latitude %> | ||
<br/> | ||
<%= f.text_field :latitude %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :longitude %> | ||
<br/> | ||
<%= f.text_field :longitude %> | ||
</div> | ||
<div class="actions"> | ||
<%= f.submit %> | ||
</div> | ||
<% end %> | ||
|
||
|
||
<input type="button" value="Find me!" onclick="findMe();" /> |
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,6 @@ | ||
<h1>Editing checkin</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Show', @checkin %> | | ||
<%= link_to 'Back', checkins_path %> |
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,62 @@ | ||
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> | ||
|
||
<div id="map" style="width: 600px; height: 500px;"></div> | ||
|
||
<h1>Listing checkins</h1> | ||
|
||
<table> | ||
<tr> | ||
<th>Title</th> | ||
<th>Location</th> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
|
||
<% @checkins.each do |checkin| %> | ||
<tr> | ||
<td><%= checkin.title %></td> | ||
<td><%= checkin.location %></td> | ||
<td><%= link_to 'Show', checkin %></td> | ||
<td><%= link_to 'Edit', edit_checkin_path(checkin) %></td> | ||
<td><%= link_to 'Destroy', checkin, confirm: 'Are you sure?', method: :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New Checkin', new_checkin_path %> | ||
|
||
<script type="text/javascript"> | ||
// Create the map | ||
var map = new google.maps.Map(document.getElementById("map"), { | ||
mapTypeId: google.maps.MapTypeId.ROADMAP | ||
}); | ||
|
||
// Initialize the bounds container | ||
var bounds = new google.maps.LatLngBounds(); | ||
|
||
<% @checkins.each do |checkin| %> | ||
// Create the LatLng | ||
var latLng = new google.maps.LatLng(<%= checkin.latitude %>, <%= checkin.longitude %>); | ||
|
||
// Create the marker | ||
var marker = new google.maps.Marker({ | ||
position: latLng, | ||
map: map, | ||
title: '<%= escape_javascript(checkin.title) %>' | ||
}); | ||
|
||
// Add click event | ||
google.maps.event.addListener(marker, 'click', function() { | ||
document.location = '<%= checkin_path(checkin) %>'; | ||
}); | ||
|
||
// Extend the bounds | ||
bounds.extend(latLng); | ||
<% end %> | ||
|
||
// Fit to bounds | ||
map.fitBounds(bounds); | ||
</script> |
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,5 @@ | ||
<h1>New checkin</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Back', checkins_path %> |
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,22 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<p> | ||
<b>Title:</b> | ||
<%= @checkin.title %> | ||
</p> | ||
|
||
<p> | ||
<b>Location:</b> | ||
<%= @checkin.location %> | ||
</p> | ||
|
||
|
||
<%= link_to 'Edit', edit_checkin_path(@checkin) %> | | ||
<%= link_to 'Back', checkins_path %> | ||
|
||
<h2>Nearby check-ins</h2> | ||
<ul> | ||
<% @nearby_checkins.each do |checkin| %> | ||
<li><%= link_to checkin.title, checkin %></li> | ||
<% end %> | ||
</ul> |
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
Oops, something went wrong.