rails-google-maps 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +60 -3
- data/lib/rails-google-maps.rb +2 -0
- data/lib/{rails_google_maps.rb → rails-google-maps/rails.rb} +0 -2
- data/lib/{rails_google_maps → rails-google-maps}/version.rb +1 -1
- data/{rails_google_maps.gemspec → rails-google-maps.gemspec} +2 -3
- data/vendor/assets/javascripts/autocomplete.js.coffee +1 -1
- data/vendor/assets/javascripts/{gmaps.js.coffee → rails_google_maps.js.coffee} +9 -5
- metadata +6 -22
- data/vendor/assets/javascripts/test.js +0 -0
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# Rails + Google Maps
|
2
2
|
|
3
|
-
|
3
|
+
* Gem provides small js library to simplify communication with google maps.
|
4
|
+
* jQuery Autocomplete integration.
|
5
|
+
|
6
|
+
Something was taken from https://github.com/rjshade/gmaps-autocomplete
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -16,9 +19,63 @@ Or install it yourself as:
|
|
16
19
|
|
17
20
|
$ gem install rails_google_maps
|
18
21
|
|
22
|
+
To use this gem you need to require google map script on the top of your layout(before including application.js).
|
23
|
+
Haml example:
|
24
|
+
```ruby
|
25
|
+
- unless Rails.env == 'test' # we don't like to load gmaps while testing
|
26
|
+
%script{:src => "http://maps.googleapis.com/maps/api/js?sensor=false", :type => "text/javascript"}
|
27
|
+
```
|
28
|
+
|
29
|
+
And include it in your ```application.js``` file after jquery:
|
30
|
+
```
|
31
|
+
//= require rails_google_maps
|
32
|
+
```
|
33
|
+
|
34
|
+
|
19
35
|
## Usage
|
20
36
|
|
21
|
-
|
37
|
+
1) Apply google map to div element where map should appear:
|
38
|
+
```js
|
39
|
+
(new GoogleMap()).apply()
|
40
|
+
```
|
41
|
+
By default it will be applied to the element with id '#gmaps-canvas', but it can be customized:
|
42
|
+
```js
|
43
|
+
(new GoogleMap({selector: '#gmaps'})).apply()
|
44
|
+
```
|
45
|
+
|
46
|
+
2) Store selected point (latitude and longitude) in input fields:
|
47
|
+
```js
|
48
|
+
new GoogleMap({longitudeInput: '#longitude_input', latitudeInput: '#latitude_input'})
|
49
|
+
```
|
50
|
+
|
51
|
+
3) Set preferred location from your code:
|
52
|
+
```js
|
53
|
+
gmap = new GoogleMap()
|
54
|
+
gmap.apply()
|
55
|
+
gmap.geocodeLookup('address', 'New York')
|
56
|
+
//or
|
57
|
+
gmap.geocodeLookup('latLng', new google.maps.LatLng(51.751724,-1.255284))
|
58
|
+
```
|
59
|
+
|
60
|
+
4) Prevent users from changing location:
|
61
|
+
```js
|
62
|
+
new GoogleMap({immutable: true})
|
63
|
+
```
|
64
|
+
|
65
|
+
5) Integrate map with jquery-autocomplete:
|
66
|
+
```js
|
67
|
+
gmap = new GoogleMap()
|
68
|
+
autoComplete = new GmapAutocomplete('#gmaps-input-address', gmap)
|
69
|
+
autoComplete.apply()
|
70
|
+
gmap.apply()
|
71
|
+
```
|
72
|
+
6) Add errors (these - are defaults):
|
73
|
+
```js
|
74
|
+
(new GoogleMap({errorField: "#gmaps-error"})).apply() // default errorField is "#gmaps-error"
|
75
|
+
GmapErrors.wrongInputText = "Sorry, something went wrong. Try again!"
|
76
|
+
GmapErrors.incorrectLatLngText = "Woah... that's pretty remote! You're going to have to manually enter a place name."
|
77
|
+
GmapErrors.incorrectAddressText = function(value){"Sorry! We couldn't find " + value + ". Try a different search term, or click the map."}
|
78
|
+
```
|
22
79
|
|
23
80
|
## Contributing
|
24
81
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'rails-google-maps/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "rails-google-maps"
|
@@ -12,12 +12,11 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.summary = 'Provides simple way to add google maps to your app'
|
13
13
|
gem.homepage = 'http://github.com/yratanov/rails_google_maps'
|
14
14
|
|
15
|
-
gem.files = `git ls-files`.split(
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ['lib']
|
19
19
|
|
20
20
|
gem.add_dependency 'rails', '~>3.0'
|
21
21
|
gem.add_dependency 'jquery-rails'
|
22
|
-
gem.add_dependency 'railties', '~> 3.1'
|
23
22
|
end
|
@@ -52,7 +52,7 @@ class root.GmapAutocomplete extends Autocomplete
|
|
52
52
|
self = this
|
53
53
|
$(@selector).bind 'keydown', (event)->
|
54
54
|
if event.keyCode == 13
|
55
|
-
self.gmap.geocodeLookup 'address', $(self.selector).val()
|
55
|
+
self.gmap.geocodeLookup 'address', $(self.selector).val()
|
56
56
|
$(self.selector).autocomplete "disable"
|
57
57
|
else
|
58
58
|
$(self.selector).autocomplete "enable"
|
@@ -11,6 +11,8 @@ class root.GoogleMap
|
|
11
11
|
|
12
12
|
#defines whether user can change map pin or not
|
13
13
|
immutable = false
|
14
|
+
mapSelector = "#gmaps-canvas"
|
15
|
+
errorField = "#gmaps-error"
|
14
16
|
|
15
17
|
_applied: false
|
16
18
|
|
@@ -22,10 +24,12 @@ class root.GoogleMap
|
|
22
24
|
|
23
25
|
# options: object options
|
24
26
|
# gmapOptions: google map api options
|
25
|
-
constructor: (options = {}, gmapOptions = {}
|
27
|
+
constructor: (options = {}, gmapOptions = {})->
|
26
28
|
@gmapOptions = $.extend {}, GoogleMap.defaultGmapOptions, gmapOptions
|
27
29
|
@immutable = true if options['immutable']
|
28
|
-
if options['
|
30
|
+
@mapSelector = options['selector'] if options['selector']
|
31
|
+
@errorField = options['errorField'] if options['errorField']
|
32
|
+
if options['longitudeInput'] and options['latitudeInput']
|
29
33
|
@saveLangLat = true
|
30
34
|
@longitudeInput = options['longitudeInput']
|
31
35
|
@latitudeInput = options['latitudeInput']
|
@@ -48,7 +52,7 @@ class root.GoogleMap
|
|
48
52
|
applied: ()->
|
49
53
|
@_applied
|
50
54
|
|
51
|
-
geocodeLookup: (type, value, update =
|
55
|
+
geocodeLookup: (type, value, update = true)->
|
52
56
|
request = {}
|
53
57
|
request[type] = value
|
54
58
|
self = this
|
@@ -63,10 +67,10 @@ class root.GoogleMap
|
|
63
67
|
self = this
|
64
68
|
return if @immutable
|
65
69
|
google.maps.event.addListener @marker, 'dragend', () ->
|
66
|
-
self.geocodeLookup 'latLng', self.marker.getPosition()
|
70
|
+
self.geocodeLookup 'latLng', self.marker.getPosition(), false
|
67
71
|
google.maps.event.addListener @map, 'click', (event) ->
|
68
72
|
self.marker.setPosition event.latLng
|
69
|
-
self.geocodeLookup 'latLng', event.latLng
|
73
|
+
self.geocodeLookup 'latLng', event.latLng, false
|
70
74
|
|
71
75
|
_succeed: (results, update)->
|
72
76
|
if results[0]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-google-maps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -43,22 +43,6 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: railties
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '3.1'
|
54
|
-
type: :runtime
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.1'
|
62
46
|
description: Provides simple way to add google maps to your app
|
63
47
|
email:
|
64
48
|
- yratanov@gmail.com
|
@@ -71,12 +55,12 @@ files:
|
|
71
55
|
- LICENSE.txt
|
72
56
|
- README.md
|
73
57
|
- Rakefile
|
74
|
-
- lib/
|
75
|
-
- lib/
|
76
|
-
-
|
58
|
+
- lib/rails-google-maps.rb
|
59
|
+
- lib/rails-google-maps/rails.rb
|
60
|
+
- lib/rails-google-maps/version.rb
|
61
|
+
- rails-google-maps.gemspec
|
77
62
|
- vendor/assets/javascripts/autocomplete.js.coffee
|
78
|
-
- vendor/assets/javascripts/
|
79
|
-
- vendor/assets/javascripts/test.js
|
63
|
+
- vendor/assets/javascripts/rails_google_maps.js.coffee
|
80
64
|
homepage: http://github.com/yratanov/rails_google_maps
|
81
65
|
licenses: []
|
82
66
|
post_install_message:
|
File without changes
|