gmap_coordinates_picker 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59458970ed9f7342bdc530e763d7cdc337b2bad4
4
+ data.tar.gz: bb9f73612af9dea0149ce82441f91f4d2a60d8a4
5
+ SHA512:
6
+ metadata.gz: 8ad3eb3aa69051fed4bbd3e5bb746508756e5f69f4336b26c27377738b3c73b7dc02c3d63c53c224fc4d0c5cec33700d1324913ac2df5252f7b726fa575f7963
7
+ data.tar.gz: 700dd165275f074eda768373b34d57763b426fd26623b77e0135fd942433dde6b5521d459d99cb2d2755919f5849736b621d111547dd3393864280b712da640c
data/README.md CHANGED
@@ -5,6 +5,11 @@ works to provide an easy to use Google Maps interface for displaying and setting
5
5
 
6
6
  Where a latitude and longitude is set on the model, it is indicated by a marker shown on a Google map centered at the marker. The administrator can change the value of these fields by clicking on the desired new location on the map.
7
7
 
8
+ Demo app source code
9
+ ====================
10
+
11
+ https://github.com/amuntasim/gmap-coordicate-picker-demo
12
+
8
13
  Usage
9
14
  =====
10
15
 
@@ -17,18 +22,18 @@ gem " gmap_coordinates_picker"
17
22
  Then, add in your form:
18
23
 
19
24
  ```ruby
20
- <%= form.gmap_coordinate_picker :lat_column => 'latitude', :lng_column => 'longitude' , :zoom_level => 10, :default_coordinates => [lat,lng] %>
25
+ <%= form.gmap_coordinate_picker api_key: GOOGLE_MAP_API_KEY, :lat_column => 'latitude', :lng_column => 'longitude' , :zoom_level => 10, :default_coordinates => [lat,lng], autocomplete: { enable: true, class: 'form-control' } %>
21
26
  ```
22
27
 
23
28
  Or, user is as form helper:
24
29
 
25
30
  ```ruby
26
- <%= render_gmap_coordinate_picker :lat_column => 'latitude', :lng_column => 'longitude' , :zoom_level => 10, :default_coordinates => [lat,lng] %>
31
+ <%= render_gmap_coordinate_picker api_key: GOOGLE_MAP_API_KEY, :lat_column => 'latitude', :lng_column => 'longitude' , :zoom_level => 10, :default_coordinates => [lat,lng], autocomplete: { enable: true, class: 'form-control' } %>
27
32
  ```
28
33
  To display static map:
29
34
 
30
35
  ```ruby
31
- <%= render_gmap_coordinate_picker :static => 'true', :zoom_level => 10 , :default_coordinates => [lat,lng] %>
36
+ <%= render_gmap_coordinate_picker api_key: GOOGLE_MAP_API_KEY, :static => 'true', :zoom_level => 10 , :default_coordinates => [lat,lng] %>
32
37
  ```
33
38
 
34
39
 
@@ -40,9 +45,10 @@ beside the option depicted on the example above it can be configured with the fo
40
45
  - `map_container_class` - custom class for the map container
41
46
  - `map_width` - default "600px
42
47
  - `map_height` - default "400px"
43
- - `api_key` - Google Map api key (optional)
48
+ - `api_key` - Google Map api key
44
49
  - 'static' - to display only static map, by default it set to false and the map will be editable
45
50
  - 'map_handler' - javascript map object to operate custom event on rendered map by default gMapObj is assigned as map object. You can implement any google map API methods like setCenter, zoom with that object
51
+ - 'autocomplete' - enable autocomplete with input class - default "{ enable: true, class: 'form-control' }"
46
52
 
47
53
  General configuration options
48
54
  =============================
@@ -50,14 +56,15 @@ General configuration options
50
56
  You can configure the following default values by overriding these values using:
51
57
  GmapCoordinatesPicker.configure method.
52
58
 
53
- lat_column #= :latitude
54
- lng_column #= :longitude
55
- default_coordinates #= [23.727666666, 90.410550] #Dhaka (my home town) center point :)
56
- map_handler #= 'gMapObj'
57
- zoom_level #= 10
58
- map_container_class #= 'gmap_coordinate_picker_container'
59
- map_width #= '600px'
60
- map_height #= '400px'
59
+ lat_column #= :latitude
60
+ lng_column #= :longitude
61
+ default_coordinates #= [23.727666666, 90.410550] #Dhaka (my home town) center point :)
62
+ map_handler #= 'gMapObj'
63
+ zoom_level #= 10
64
+ map_container_class #= 'gmap_coordinate_picker_container'
65
+ map_width #= '600px'
66
+ map_height #= '400px'
67
+ autocomplete #= { enable: true, class: 'form-control' }
61
68
 
62
69
  There's a handy generator that generates the default configuration file into config/initializers directory.
63
70
  Run the following generator command, then edit the generated file.
@@ -68,6 +75,8 @@ rails g gmap_coordinates_picker:config
68
75
 
69
76
  VERSION
70
77
  =======
78
+ -0.1.0
79
+ - Rails4 support
71
80
 
72
81
  -0.0.3
73
82
  - `static map` feature added
@@ -1,10 +1,13 @@
1
- <%= javascript_include_tag ("http://maps.googleapis.com/maps/api/js?key=#{api_key}&sensor=false") %>
1
+ <% autocomplete = autocomplete || {} %>
2
2
  <script type="text/javascript">
3
3
  var <%= map_handler%> = <%= map_handler%> || {};
4
+ var <%= map_handler%>Marker = <%= map_handler%>Marker || {};
5
+
6
+ var afterGmapLoaded = function(){
4
7
 
5
- jQuery(function () {
6
8
  var marker = null;
7
- var latlng = new google.maps.LatLng(<%= default_coordinates[0]%>, <%=default_coordinates[1] %>);
9
+ var latlng = new google.maps.LatLng(<%= lat_column_value || default_coordinates[0]%>, <%=lng_column_value || default_coordinates[1] %>);
10
+
8
11
 
9
12
  var myOptions = {
10
13
  zoom: <%=zoom_level %>,
@@ -20,12 +23,26 @@
20
23
  position:new google.maps.LatLng(<%= lat_column_value%>,<%=lng_column_value %>),
21
24
  map:map
22
25
  });
23
- <% end%>
26
+ <% end%>
27
+ <%= map_handler%>Marker = marker;
24
28
 
25
29
  google.maps.event.addListener(map, 'click', function(e) {
26
30
  updateLocation(e.latLng);
27
31
  });
28
32
 
33
+ <% if autocomplete[:enable] %>
34
+ var input = document.getElementById('searchInput');
35
+ var autocomplete = new google.maps.places.Autocomplete(input);
36
+ autocomplete.bindTo('bounds', map);
37
+
38
+ autocomplete.addListener('place_changed', function() {
39
+ var place = autocomplete.getPlace();
40
+ var location = place.geometry.location;
41
+ updateLocation(location)
42
+ return;
43
+ });
44
+ <% end %>
45
+
29
46
  function updateLocation(location) {
30
47
  if(marker) {
31
48
  marker.setPosition(location);
@@ -35,14 +52,30 @@
35
52
  map: map
36
53
  });
37
54
  }
55
+ <%= map_handler%>Marker = marker;
38
56
 
39
57
  map.setCenter(location);
40
58
  jQuery("#<%= lat_dom_id%>").val(location.lat());
41
59
  jQuery("#<%=lng_dom_id %>").val(location.lng());
42
60
  }
43
61
 
44
- });
62
+
63
+ }
64
+ if (typeof window.google == 'undefined' || typeof google.maps == 'undefined'){
65
+ $.getScript('<%= "http://maps.googleapis.com/maps/api/js?key=#{api_key}" %>', function(){
66
+ afterGmapLoaded()
67
+ });
68
+ }else {
69
+ afterGmapLoaded();
70
+ }
71
+
45
72
  </script>
73
+ <% if autocomplete[:enable] %>
74
+ <div>
75
+ <input type='text' class='<%= autocomplete[:class] %>' id='searchInput'/>
76
+ </div>
77
+ <br/>
78
+ <% end %>
46
79
  <div class="<%= map_container_class%>" id="<%=map_container%>" style="<%= "width:#{map_width};height:#{map_height}"%>">
47
80
  </div>
48
81
  <%= lat_field%>
@@ -1,4 +1,4 @@
1
- <%= javascript_include_tag ("http://maps.googleapis.com/maps/api/js?key=#{api_key}&sensor=false") %>
1
+ <%= javascript_include_tag ("http://maps.googleapis.com/maps/api/js?key=#{api_key}") %>
2
2
  <script type="text/javascript">
3
3
  var <%= map_handler%> = <%= map_handler%> || {};
4
4
 
@@ -22,6 +22,7 @@ module GmapCoordinatesPicker
22
22
  config_accessor :map_container_class
23
23
  config_accessor :map_width
24
24
  config_accessor :map_height
25
+ config_accessor :autocomplete
25
26
  end
26
27
 
27
28
  configure do |config|
@@ -30,6 +31,7 @@ module GmapCoordinatesPicker
30
31
  config.default_coordinates = [23.727666666, 90.410550] #Dhaka (my home town) center point :)
31
32
  config.map_handler = 'gMapObj'
32
33
  config.zoom_level = 10
34
+ config.autocomplete = { enable: false, class: 'form-control'}
33
35
  config.map_container_class = 'gmap_coordinate_picker_container'
34
36
  config.map_width = '600px'
35
37
  config.map_height = '400px'
@@ -1,3 +1,3 @@
1
1
  module GmapCoordinatesPicker
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -10,9 +10,10 @@ module GmapCoordinatesPicker #:nodoc
10
10
  lat_column = options[:lat_column] || options[:gmap_conf][:lat_column] || GmapCoordinatesPicker.config.lat_column
11
11
  lng_column = options[:lng_column] || options[:gmap_conf][:lng_column] || GmapCoordinatesPicker.config.lng_column
12
12
  default_coordinates = options[:default_coordinates] || GmapCoordinatesPicker.config.default_coordinates
13
- lat_column_value = options[:object].present? ? options[:object].send(lat_column) : default_coordinates[0]
14
- lng_column_value = options[:object].present? ? options[:object].send(lng_column) : default_coordinates[1]
13
+ lat_column_value = options[:object].present? ? options[:object].send(lat_column) || default_coordinates[0] : default_coordinates[0]
14
+ lng_column_value = options[:object].present? ? options[:object].send(lng_column) || default_coordinates[1] : default_coordinates[1]
15
15
  prefix = options[:object].present? ? options[:object].class.name.downcase : "gmap_coordinate_picker"
16
+ autocomplete = options[:autocomplete] || GmapCoordinatesPicker.config.autocomplete
16
17
  lat_dom_id = "#{prefix}_#{lat_column}"
17
18
  lng_dom_id = "#{prefix}_#{lng_column}"
18
19
  end
@@ -25,7 +26,8 @@ module GmapCoordinatesPicker #:nodoc
25
26
  :map_container_class => options[:map_container_class] || GmapCoordinatesPicker.config.map_container_class,
26
27
  :map_width => options[:map_width] || GmapCoordinatesPicker.config.map_width,
27
28
  :map_height => options[:map_height] || GmapCoordinatesPicker.config.map_height,
28
- :default_coordinates => options[:default_coordinates] || GmapCoordinatesPicker.config.default_coordinates,
29
+ :autocomplete => options[:autocomplete] || GmapCoordinatesPicker.config.autocomplete,
30
+ :default_coordinates => default_coordinates.empty? ? GmapCoordinatesPicker.config.default_coordinates : options[:default_coordinates],
29
31
  }
30
32
 
31
33
  editable_map_locals = {
@@ -37,6 +39,7 @@ module GmapCoordinatesPicker #:nodoc
37
39
  :map_container => "#{prefix}_#{lat_column}_#{lng_column}_container#{Time.now.to_i}",
38
40
  :lat_dom_id => lat_dom_id,
39
41
  :lng_dom_id => lng_dom_id,
42
+ :autocomplete => autocomplete,
40
43
  :lat_field => lat_lng_field(lat_column, lat_column_value, lat_dom_id, options),
41
44
  :lng_field => lat_lng_field(lng_column, lng_column_value, lng_dom_id, options)
42
45
  }
metadata CHANGED
@@ -1,32 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmap_coordinates_picker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Muntasim Ahmed
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-28 00:00:00.000000000 Z
11
+ date: 2018-04-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.1.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6'
22
23
  type: :runtime
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: 3.1.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6'
30
33
  description: It works without any dependency to any third party library
31
34
  email:
32
35
  - ahmed2tul@gmail.com
@@ -34,43 +37,42 @@ executables: []
34
37
  extensions: []
35
38
  extra_rdoc_files: []
36
39
  files:
40
+ - MIT-LICENSE
41
+ - README.md
42
+ - Rakefile
37
43
  - app/views/gmap_coordinate_picker/_gmap_coordinate_picker.html.erb
38
44
  - app/views/gmap_coordinate_picker/_render_map.html.erb
39
45
  - lib/generators/gmap_coordinates_picker/config_generator.rb
40
46
  - lib/generators/gmap_coordinates_picker/templates/gmap_coordinates_picker_config.rb
47
+ - lib/gmap_coordinates_picker.rb
41
48
  - lib/gmap_coordinates_picker/config.rb
42
49
  - lib/gmap_coordinates_picker/engine.rb
43
50
  - lib/gmap_coordinates_picker/form_builder.rb
44
51
  - lib/gmap_coordinates_picker/formtastic.rb
45
52
  - lib/gmap_coordinates_picker/version.rb
46
53
  - lib/gmap_coordinates_picker/view_helper.rb
47
- - lib/gmap_coordinates_picker.rb
48
- - MIT-LICENSE
49
- - Rakefile
50
- - README.md
51
54
  homepage: ''
52
55
  licenses: []
56
+ metadata: {}
53
57
  post_install_message:
54
58
  rdoc_options: []
55
59
  require_paths:
56
60
  - lib
57
61
  required_ruby_version: !ruby/object:Gem::Requirement
58
- none: false
59
62
  requirements:
60
- - - ! '>='
63
+ - - ">="
61
64
  - !ruby/object:Gem::Version
62
65
  version: '0'
63
66
  required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
67
  requirements:
66
- - - ! '>='
68
+ - - ">="
67
69
  - !ruby/object:Gem::Version
68
70
  version: '0'
69
71
  requirements: []
70
72
  rubyforge_project:
71
- rubygems_version: 1.8.25
73
+ rubygems_version: 2.2.2
72
74
  signing_key:
73
- specification_version: 3
75
+ specification_version: 4
74
76
  summary: works to provide an easy to use Google Maps interface for displaying and
75
77
  setting geographic co-ordinates
76
78
  test_files: []