Giter Club home page Giter Club logo

bbq / google-maps-for-rails Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apneadiving/google-maps-for-rails

1.0 2.0 0.0 1.04 MB

Enables easy display of items (taken from a Rails 3 model) with Google Map, OpenLayers, Bing or Mapquest. Geocoding + Directions included. Provides much options: markers customization, infowindows, auto-adjusted zoom, polylines, polygons, circles etc... See wiki for full description and examples.

Home Page: https://rubygems.org/gems/gmaps4rails

License: MIT License

google-maps-for-rails's Introduction

Google Maps for Rails (gmaps4rails)

Gmaps4rails is developped to simply create a Google Map:

  • directly from your model,

  • from your own json

It’s based on Ruby on Rails 3 Engines and uses Google Maps API V3.

See (somewhat outdated) screencasts here: www.youtube.com/user/TheApneadiving

When Gmaps4rails finally means Global Maps for Rails

I’ve added support for other map providers:

  • openlayers

  • mapquest

  • bing

See: github.com/apneadiving/Google-Maps-for-Rails/wiki/Map-Apis

Any help would be appreciated to complete this work.

Requirements

  • gem ‘gmaps4rails’ (in your gemfile, then bundle)

  • <%= yield :head %> (in your header)

  • <%= yield :scripts %> (in your footer)

To make Rails serve the assets (javascripts, stylesheets and marker images) you have several options, depending on your configuration and Rails version:

  • if you are using Rails 3.1 and have asset pipeline enabled (‘config.assets.enabled = true’ in config/application.rb), include the appropriate manifest:

    • //= require gmaps4rails/bing.js

    • //= require gmaps4rails/googlemaps.js

    • //= require gmaps4rails/mapquest.js

    • //= require gmaps4rails/openlayers.js

    • //= require gmaps4rails/all_apis.js

    You even don’t need the ‘yield :head` if you include `require gmaps4rails` in your CSS manifest.

  • if you are using Rails 3.0: see para below to be sure everything will work in production.

  • finally you can just copy assets to your application’s public/stylesheets, public/javascripts/gmaps4rails and public/images. It’s recommended to do this in production so that you can let your webserver serve them rather than go through Rails each time they are requested. There’s a generator to help you with that:

    rails generate gmaps4rails:install
    

    This will copy the coffeescript files if you’re running Rails 3.1 or the js files for Rails 3.0.x

Basic configuration

In your model, add:

acts_as_gmappable

def gmaps4rails_address
  #describe how to retrieve the address from your model, if you use directly a db column, you can dry your code, see wiki
  "#{self.street}, #{self.city}, #{self.country}" 
end

Create a migration and add the following fields to your table (here users):

add_column :users, :latitude, :float #you can change the name, see wiki
add_column :users, :longitude, :float #you can change the name, see wiki
add_column :users, :gmaps, :boolean #not mandatory, see wiki

How to?

QuickStart!

In your controller:

@json = User.all.to_gmaps4rails

In your view:

<%= gmaps4rails(@json) %>

Done!

Options

  • Markers with Info window, Custom Picture, RichMarkers (make your own markers with custom html)

  • Automatic sidebar with list of markers

  • Circles, Polylines, Polygons

  • Geocode directly your address and retrieve coordinates.

  • Wrapper for ‘Direction’, giving instructions to go from point A to point B

  • Auto-adjust the map to your markers

  • Refresh your map on the fly with Javascript (and Ajax)

  • KML support

  • Easy multimap

  • More details in the Wiki

Todo?

Feel free ton contact us, you have your say.

MIT license.

Authors: Benjamin Roth, David Ruyer

Contributors: Mircea Pricop, Kamil Śliwak, Alex Vorobiev

google-maps-for-rails's People

Contributors

apneadiving avatar jmcopeland avatar avioing avatar cameel avatar davidruru avatar oli-g avatar raid5 avatar libo avatar joeytheman avatar przemad avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.