Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

map

  • Loading branch information...
commit 24852aacb1a511152e6e8a77c3ae52d357f28bcc 1 parent ff54ba3
@ebner authored
View
27 app/controllers/locations_controller.rb
@@ -1,5 +1,14 @@
class LocationsController < ApplicationController
+ def index
+ @locations = Location.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render :json => @items }
+ end
+ end
+
def show
@json = Location.all.to_gmaps4rails do |location, marker|
# marker.infowindow render_to_string(:partial => "/users/my_template", :locals => { :object => user})
@@ -27,6 +36,24 @@ def show
end
def edit
+
end
+ def new
+
+ end
+
+ def update
+ @user = User.find(current_user.id)
+ if @user.location
+ @location = @user.location
+ else
+ @location = Location.new
+ @location.user_id = @user.id
+ end
+ @location.lat = params[:latitude]
+ @location.long = params[:latitude]
+ @location.save
+ end
+
end
View
87 app/views/locations/_form.html.erb
@@ -0,0 +1,87 @@
+<script type="text/javascript" src='http://maps.google.com/maps/api/js?sensor=false'></script>
+
+<script type="text/javascript">
+ $(document).ready(function() {
+
+ var Circle = null;
+ var Radius = $("#radius").val();
+
+ var StartPosition = new google.maps.LatLng(60, 15);
+
+ function DrawCircle(Map, Center, Radius) {
+
+ if(Circle != null) {
+ Circle.setMap(null);
+ }
+
+ if(Radius > 0) {
+ Radius *= 1609.344;
+ Circle = new google.maps.Circle({
+ center : Center,
+ radius : Radius,
+ strokeColor : "#0000FF",
+ strokeOpacity : 0.35,
+ strokeWeight : 2,
+ fillColor : "#0000FF",
+ fillOpacity : 0.20,
+ map : Map
+ });
+ }
+ }
+
+ function SetPosition(Location, Viewport) {
+ Marker.setPosition(Location);
+ if(Viewport) {
+ Map.fitBounds(Viewport);
+ Map.setZoom(map.getZoom() + 2);
+ } else {
+ Map.panTo(Location);
+ }
+ Radius = $("#radius").val();
+ DrawCircle(Map, Location, Radius);
+ $("#latitude").val(Location.lat().toFixed(5));
+ $("#longitude").val(Location.lng().toFixed(5));
+ }
+
+ var MapOptions = {
+ zoom : 5,
+ center : StartPosition,
+ mapTypeId : google.maps.MapTypeId.ROADMAP,
+ mapTypeControl : false,
+ disableDoubleClickZoom : true,
+ streetViewControl : false
+ };
+
+ var MapView = $("#map");
+ var Map = new google.maps.Map(MapView.get(0), MapOptions);
+
+ var Marker = new google.maps.Marker({
+ position : StartPosition,
+ map : Map,
+ title : "Drag Me",
+ draggable : true
+ });
+
+ google.maps.event.addListener(Marker, "dragend", function(event) {
+ SetPosition(Marker.position);
+ });
+
+ $("#radius").keyup(function() {
+ google.maps.event.trigger(Marker, "dragend");
+ });
+ DrawCircle(Map, StartPosition, Radius);
+ SetPosition(Marker.position);
+
+ });
+
+</script>
+
+<form action='/locations'>
+ Lat <input type="text" id="latitude" size="6" />
+ Long <input type="text" id="longitude" size="6" />
+ Radius <input type="text" id="radius" value="50" size="6" />
+ <input type='submit' value='Save' />
+ <br /> <br />
+ <div id="map" style="width:600px; height:400px; background-color:#000000;"></div>
+</form>
+</div>
View
91 app/views/locations/edit.html.erb
@@ -1,89 +1,6 @@
-<% enable_css = false%>
-
-<script type="text/javascript" src='http://maps.google.com/maps/api/js?sensor=false'></script>
-
-<script type="text/javascript">
- $(document).ready(function() {
-
- var Circle = null;
- var Radius = $("#radius").val();
-
- var StartPosition = new google.maps.LatLng(60, 15);
-
- function DrawCircle(Map, Center, Radius) {
-
- if(Circle != null) {
- Circle.setMap(null);
- }
-
- if(Radius > 0) {
- Radius *= 1609.344;
- Circle = new google.maps.Circle({
- center : Center,
- radius : Radius,
- strokeColor : "#0000FF",
- strokeOpacity : 0.35,
- strokeWeight : 2,
- fillColor : "#0000FF",
- fillOpacity : 0.20,
- map : Map
- });
- }
- }
-
- function SetPosition(Location, Viewport) {
- Marker.setPosition(Location);
- if(Viewport) {
- Map.fitBounds(Viewport);
- Map.setZoom(map.getZoom() + 2);
- } else {
- Map.panTo(Location);
- }
- Radius = $("#radius").val();
- DrawCircle(Map, Location, Radius);
- $("#latitude").val(Location.lat().toFixed(5));
- $("#longitude").val(Location.lng().toFixed(5));
- }
-
- var MapOptions = {
- zoom : 5,
- center : StartPosition,
- mapTypeId : google.maps.MapTypeId.ROADMAP,
- mapTypeControl : false,
- disableDoubleClickZoom : true,
- streetViewControl : false
- };
-
- var MapView = $("#map");
- var Map = new google.maps.Map(MapView.get(0), MapOptions);
-
- var Marker = new google.maps.Marker({
- position : StartPosition,
- map : Map,
- title : "Drag Me",
- draggable : true
- });
-
- google.maps.event.addListener(Marker, "dragend", function(event) {
- SetPosition(Marker.position);
- });
-
- $("#radius").keyup(function() {
- google.maps.event.trigger(Marker, "dragend");
- });
- DrawCircle(Map, StartPosition, Radius);
- SetPosition(Marker.position);
-
- });
+<div id="text">
+<h1>Editing location</h1>
-</script>
+<%= render 'form' %>
-<div id="text">
-<form>
- Lat <input type="text" id="latitude" size="6" />
- Long <input type="text" id="longitude" size="6" />
- Radius <input type="text" id="radius" value="50" size="6" />
- <br /> <br />
- <div id="map" style="width:600px; height:400px; background-color:#000000;"></div>
-</form>
-</div>
+</div>
View
6 app/views/locations/index.html.erb
@@ -0,0 +1,6 @@
+<div id="text">
+<h1>Editing location</h1>
+
+<%= render 'form' %>
+
+</div>
View
5 config/routes.rb
@@ -3,6 +3,9 @@
devise_for :users
resources :users
resources :locations
+
+ match 'locationedit' => 'locations#edit'
+
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -13,7 +16,7 @@
match 'my_items' => 'items#my_items'
match 'about' => 'items#about'
match 'search' => 'items#search'
- match 'users/edit/location' => 'locations#edit'
+
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
Please sign in to comment.
Something went wrong with that request. Please try again.