gmap_point_picker 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ad4977167bf0cf5cf5ddb8b98459815b9e04d44
4
- data.tar.gz: ef843f824ef42bbf8a5006a2da338f73864701a0
3
+ metadata.gz: 3319fd270fbe00157bfe70dc26349e90ff2d1cd2
4
+ data.tar.gz: 1b34e05f9303026d98e1dba352145906c644d7a3
5
5
  SHA512:
6
- metadata.gz: 03d605b07845ea19fc789a65974f301861c4992cde26a9ec106d7c93f30ef70c597fd6e6e9fc7cf4143fcc98f67fe64c1f3bd6b76f3425340a817307b7f83378
7
- data.tar.gz: 05ef2865ec09e1e4f92014edb04cedab5ceb704d3d1a404becf8df2bd87514382272fb3c8956656783784f4084d6664f9a2fa1402232d76e4f0bd3890b283f9a
6
+ metadata.gz: 18c927677833bdfd9286305249fd2711bb67c3a680c13f52ac9714c5a948266cb73d7d4d1e616081e929443c8cd5664ef5a596ea49ea3cf50aaaf4ea6046f6b4
7
+ data.tar.gz: 99bcff68720256416b4266d95ac6ce9a325fafc7d3ab7e1997bbe5ef8b42480e229574bb06583b10292fca70da14be76cef9446baabc5b7c4ea3b4305b235ba7
data/README.rdoc CHANGED
@@ -1,38 +1,72 @@
1
- # GmapPointPicker
1
+ = GmapPointPicker
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gmap_point_picker`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This light-weigh gem allows you to bind input fields to google map's click action. The fields get populated with the latitude and longitude of the location clicked on the map.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
5
+ == Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
10
8
 
11
- ```ruby
12
- gem 'gmap_point_picker'
13
- ```
9
+ +gem 'gmap_point_picker'+
14
10
 
15
11
  And then execute:
16
12
 
17
- $ bundle
13
+ +$ bundle install+
18
14
 
19
15
  Or install it yourself as:
20
16
 
21
17
  $ gem install gmap_point_picker
22
18
 
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
19
+ == Usage
20
+ === GmapPointPicker.configure
21
+
22
+ You may use the block style configuration. The following code could be placed
23
+ into a +config/initializers/gmap_point_picker.rb+ when used in a Rails project.
24
+
25
+ GmapPointPicker.configure do |config|
26
+ config.api_key = 'xxxxxxxyyyyzzzzzzzzz' #Required if config.load_js = true
27
+ config.load_js = boolean #default false
28
+ config.latitude = "48.32324234"
29
+ config.longitude = "-78.23232343" #These are required for initial map center
30
+ config.map_div_id = "map-canvas" #div id which will be used to load the map. default 'map-canvas'
31
+ config.lat_field_id = "latitude" #input field id where latitude will be populated on click. default 'latitude'
32
+ config.lng_field_id = "longitude" #input field id where longitude will be populated on click. default 'longitude'
33
+ end
34
+
35
+ These configurations can be overridden when calling
36
+ +gmap_point_picker_bind+
37
+ OR
38
+ +gmap_point_picker_bind_no_jquery+
39
+
40
+ == Example
41
+ <%= gmap_point_picker_bind :key => "your_api_key_here",
42
+ :latitude => 34.2323232, #Center
43
+ :longitude => -78.423232,
44
+ :map_div_id => 'map-canvas', #Div for map
45
+ :load_js => true, #Should we load the google maps api for you?
46
+ :search_field_id => 'gmap-search', #Text box for searching on map
47
+ :lat_field_id => 'latitude', #Fields that will be populated on map click
48
+ :lng_field_id => 'longitude'
49
+ %>
50
+
51
+ <div>
52
+ <input type="text" id="latitude" /><br />
53
+ <input type="text" id="longitude" /><br />
54
+ <input type="text" id="gmap-search" />
55
+ </div>
56
+ <div id="map-canvas" style="height:600px;"></div>
57
+
58
+ If you do not have jQuery loaded, you can use the alternative +gmap_point_picker_bind_no_jquery+ with the same options.
59
+
60
+
61
+ == Development
28
62
 
29
63
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
64
 
31
65
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
66
 
33
- ## Contributing
67
+ == Contributing
34
68
 
35
- 1. Fork it ( https://github.com/[my-github-username]/gmap_point_picker/fork )
69
+ 1. Fork it ( https://github.com/laiqjafri/gmap_point_picker/fork )
36
70
  2. Create your feature branch (`git checkout -b my-new-feature`)
37
71
  3. Commit your changes (`git commit -am 'Add some feature'`)
38
72
  4. Push to the branch (`git push origin my-new-feature`)
@@ -80,5 +80,86 @@ module GmapPointPicker
80
80
  EOS
81
81
  return (html.respond_to?(:html_safe) && html.html_safe) || html
82
82
  end
83
+
84
+ def gmap_point_picker_bind_no_jquery options={}
85
+ key = options[:key] ||= GmapPointPicker.configuration.api_key
86
+ load_js = options[:load_js] ||= GmapPointPicker.configuration.load_js
87
+ lat_field_id = options[:lat_field_id] ||= GmapPointPicker.configuration.lat_field_id
88
+ lng_field_id = options[:lng_field_id] ||= GmapPointPicker.configuration.lng_field_id
89
+ map_div_id = options[:map_div_id] ||= GmapPointPicker.configuration.map_div_id
90
+ latitude = options[:latitude] ||= GmapPointPicker.configuration.latitude
91
+ longitude = options[:longitude] ||= GmapPointPicker.configuration.longitude
92
+ search_field_id = options[:search_field_id] ||= GmapPointPicker.configuration.search_field_id
93
+
94
+ html = ""
95
+
96
+ if load_js
97
+ html << <<-EOS
98
+ <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=#{key}&libraries=places"></script>
99
+ EOS
100
+ end
101
+
102
+ html << <<-EOS
103
+ <script>
104
+ document.addEventListener("DOMContentLoaded", function(event) {
105
+ var marker = false;
106
+ var center, input, map, search_box;
107
+ if (!document.getElementById("#{map_div_id}")) {
108
+ return;
109
+ }
110
+ center = new google.maps.LatLng(#{latitude}, #{longitude});
111
+ map = new google.maps.Map(document.getElementById("#{map_div_id}"), {
112
+ mapTypeId: google.maps.MapTypeId.ROADMAP,
113
+ center: center
114
+ });
115
+ map.setZoom(16);
116
+ input = document.getElementById("#{search_field_id}");
117
+ search_box = new google.maps.places.SearchBox(input);
118
+ google.maps.event.addListener(search_box, "places_changed", function() {
119
+ var bounds, i, image, place, places;
120
+ places = search_box.getPlaces();
121
+ i = 0;
122
+ bounds = new google.maps.LatLngBounds();
123
+ place = void 0;
124
+ place = places[0];
125
+ if (place) {
126
+ image = {
127
+ url: place.icon,
128
+ size: new google.maps.Size(71, 71),
129
+ origin: new google.maps.Point(0, 0),
130
+ anchor: new google.maps.Point(17, 34),
131
+ scaledSize: new google.maps.Size(25, 25)
132
+ };
133
+ bounds.extend(place.geometry.location);
134
+ }
135
+ map.fitBounds(bounds);
136
+ if (map.getZoom() > 16) {
137
+ map.setZoom(16);
138
+ }
139
+ return google.maps.event.addListener(map, "bounds_changed", function() {
140
+ bounds = map.getBounds();
141
+ return search_box.setBounds(bounds);
142
+ });
143
+ });
144
+ return google.maps.event.addListener(map, "click", function(event) {
145
+ var location, mapZoom;
146
+ mapZoom = map.getZoom();
147
+ location = event.latLng;
148
+ document.getElementById("#{lat_field_id}").value = location.lat();
149
+ document.getElementById("#{lng_field_id}").value = location.lng();
150
+ if (marker) {
151
+ marker.setMap(null);
152
+ }
153
+ return marker = new google.maps.Marker({
154
+ position: event.latLng,
155
+ map: map,
156
+ title: "GmapPointPicker"
157
+ });
158
+ });
159
+ });
160
+ </script>
161
+ EOS
162
+ return (html.respond_to?(:html_safe) && html.html_safe) || html
163
+ end
83
164
  end # JavascriptHelper
84
165
  end # GmapPointPicker
@@ -1,3 +1,3 @@
1
1
  module GmapPointPicker
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmap_point_picker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laiq Jafri
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -51,7 +51,6 @@ files:
51
51
  - CODE_OF_CONDUCT.md
52
52
  - Gemfile
53
53
  - LICENSE.txt
54
- - README.md
55
54
  - README.rdoc
56
55
  - Rakefile
57
56
  - bin/console
@@ -83,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
82
  version: '0'
84
83
  requirements: []
85
84
  rubyforge_project:
86
- rubygems_version: 2.2.2
85
+ rubygems_version: 2.4.7
87
86
  signing_key:
88
87
  specification_version: 4
89
88
  summary: A gem to easily pick co-ordinates from google map and map them to input fields
data/README.md DELETED
@@ -1,39 +0,0 @@
1
- # GmapPointPicker
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gmap_point_picker`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'gmap_point_picker'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install gmap_point_picker
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- 1. Fork it ( https://github.com/[my-github-username]/gmap_point_picker/fork )
36
- 2. Create your feature branch (`git checkout -b my-new-feature`)
37
- 3. Commit your changes (`git commit -am 'Add some feature'`)
38
- 4. Push to the branch (`git push origin my-new-feature`)
39
- 5. Create a new Pull Request