has_geo_lookup 0.2.1 → 0.2.3

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
  SHA256:
3
- metadata.gz: c346daadf2a1be6115c2c5a5568f3298a90fa7320b8418ffbb1404c48f1e3be4
4
- data.tar.gz: 39fbae916da78a3aa2646e5ef0770f67fb65d15d37b276e9963f045354974882
3
+ metadata.gz: 82a2c8b2c21d67e5d152996defdec6f75ef9e9263a705f21b246be6f4861e176
4
+ data.tar.gz: 6ebb46f72eb51a01d7fc916657d5d1749f8277adecf64cc352e372e02d839023
5
5
  SHA512:
6
- metadata.gz: b116a1d609b20c28140e37cf62389b520d4caef383a6abf34e9eacd7b60415929ac3ea9ad464f0ea15abf9fb563d59375dbc47eabdb860b4a19e08944777b2a0
7
- data.tar.gz: df4d371bd9667eb8605a32dafbd23271e00b86bfb16a4e38f2d328a294c8e97789c2cec9a87802d4badf2ebfa85b952003d020df9923b8ee5f4175570108403d
6
+ metadata.gz: 371d3ec0afad3359fe29606ce113e8747acccad689ea99f9b3717c7e9a8b60210daad34fc1b3b15cc6ddc7670c2571953770e77b8b6bd19a1fdb35b7d6fcabf7
7
+ data.tar.gz: 2611a686994d9e8c7af9cdcb3102eb9b83f6cad94c0908790c3ca78f2068d15174603b3ceb73b7aaa8424d358469ea1713e88d87c6020b8fb855ca5a8c5714a8
@@ -248,7 +248,27 @@ module HasGeoLookup
248
248
 
249
249
  # Fallback to closest geoname approach
250
250
  geoname_result = closest_county_or_parish
251
- return geoname_result if geoname_result
251
+ if geoname_result && geoname_result.record
252
+ # Try coordinate bridge: use geoname coordinates to find GeoBoundaries match
253
+ # This improves language consistency (e.g., "Lisbon" → "Lisboa")
254
+ geoname_lat = geoname_result.record.latitude
255
+ geoname_lng = geoname_result.record.longitude
256
+
257
+ if geoname_lat && geoname_lng
258
+ # Create temporary checker at geoname coordinates
259
+ temp_checker = Object.new.extend(HasGeoLookup)
260
+ temp_checker.define_singleton_method(:latitude) { geoname_lat }
261
+ temp_checker.define_singleton_method(:longitude) { geoname_lng }
262
+
263
+ bridge_boundary = temp_checker.containing_boundary('ADM2')
264
+ if bridge_boundary
265
+ return GeoboundaryResult.new(bridge_boundary, geoname_result.distance_km, 'ADM2', bridge_boundary.name)
266
+ end
267
+ end
268
+
269
+ # If coordinate bridge fails, use original geoname result
270
+ return geoname_result
271
+ end
252
272
 
253
273
  nil
254
274
  end
@@ -54,12 +54,12 @@ class Geoboundary < ActiveRecord::Base
54
54
  }
55
55
 
56
56
  scope :containing_point, ->(latitude, longitude) {
57
- where("ST_Contains(boundary, ST_GeomFromText(?, 4326))", "POINT(#{longitude} #{latitude})")
57
+ where("ST_Contains(boundary, ST_GeomFromText(?, 4326))", "POINT(#{latitude} #{longitude})")
58
58
  }
59
59
 
60
60
  # Check if this boundary contains the given coordinates
61
61
  #
62
- # Uses PostGIS ST_Contains function to perform precise geometric containment
62
+ # Uses MySQL ST_Contains function to perform precise geometric containment
63
63
  # testing against the boundary polygon.
64
64
  #
65
65
  # @param latitude [Float] Latitude in decimal degrees
@@ -72,7 +72,7 @@ class Geoboundary < ActiveRecord::Base
72
72
  def contains_point?(latitude, longitude)
73
73
  return false unless latitude && longitude && boundary
74
74
 
75
- point_wkt = "POINT(#{longitude} #{latitude})"
75
+ point_wkt = "POINT(#{latitude} #{longitude})"
76
76
 
77
77
  self.class.connection.select_value(
78
78
  "SELECT ST_Contains(ST_GeomFromText(?), ST_GeomFromText(?, 4326)) AS contains",
@@ -45,13 +45,13 @@ class Metro < ActiveRecord::Base
45
45
  scope :containing_point, ->(latitude, longitude) {
46
46
  joins(:geoboundaries)
47
47
  .where("ST_Contains(geoboundaries.boundary, ST_GeomFromText(?, 4326))",
48
- "POINT(#{longitude} #{latitude})")
48
+ "POINT(#{latitude} #{longitude})")
49
49
  .distinct
50
50
  }
51
51
 
52
52
  # Check if this metro contains the given coordinates
53
53
  #
54
- # Uses PostGIS spatial queries against all associated geoboundaries to determine
54
+ # Uses MySQL spatial queries against all associated geoboundaries to determine
55
55
  # if the point falls within any boundary that defines this metropolitan area.
56
56
  #
57
57
  # @param latitude [Float] Latitude in decimal degrees
@@ -68,7 +68,7 @@ class Metro < ActiveRecord::Base
68
68
  # Check if point is contained within any of the metro's boundaries
69
69
  geoboundaries.joins("INNER JOIN geoboundaries gb ON gb.id = geoboundaries.id")
70
70
  .where("ST_Contains(gb.boundary, ST_GeomFromText(?, 4326))",
71
- "POINT(#{longitude} #{latitude})")
71
+ "POINT(#{latitude} #{longitude})")
72
72
  .exists?
73
73
  rescue => e
74
74
  Rails.logger.warn "Error checking metro point containment: #{e.message}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HasGeoLookup
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_geo_lookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Edlund