vlado/earthquake-croatia

Implement google maps autocomplete and geotag ads

berislavbabic opened this issue · 5 comments

We should implement google maps autocomplete, and store the proper ad location (lat/lon) in our database. This way we will make it easier to sync with other relief apps that only have the location stored.

How to do it in rails:
https://gorails.com/episodes/google-maps-places-autocomplete-with-rails?autoplay=1

vlado commented

Let's see if finances will allow this.

Gmaps Places API says we have $200 free monthly usage and "Geocoding - Convert addresses to and from geographic coordinates" = $5/1000 requests. Which gives us 40k requests/mo. That should do it.
https://cloud.google.com/maps-platform/pricing

I've also used Mapbox (for displaying the map), but I haven't tried their Geocoding API.
https://docs.mapbox.com/help/glossary/geocoding/

NOTE: Google Maps API has a limit that you cannot use its API with another mapping software (not Google Maps) for rendering. So you cannot use Gmaps Geocoding and then render the results on a Mapbox map.

Speaking of geo-related functionality, I always add 'activerecord-postgis-adapter' and 'rgeo-geojson' gems, together with 'postgis' heroku extension (available on all plans).

This gives us consistent GeoJSON format stored in the database and also queries like this one:

  scope :within, ->(lat, lng, distance_in_km = 1) do
    # lonlat is one column (GeoJSON POINT)
    where("ST_Distance(lonlat, 'POINT(%f %f)') < %d", lng, lat, distance_in_km * 1000)
  end
vlado commented

I haven't worked on geo-related stuff much. Maybe year ago we had to do some simple geo search and we used https://github.com/geokit/geokit-rails cause it was easier to setup.

It requires just 2 columns in the db (lat, lng) and queries look like this
Location.within(5, :units => :kms, :origin => [50.9438245, 6.9400448])

That would be awesome to have, not only to have more accurate data but also to sync with other projects like Berislav said.