Rails Geocoder MapIt functionality alternatives - ruby-on-rails

I'm working with rails, geocoder and gmap4rails. Trying to figure out how to show boundaries of an ward district area in UK. Found mapit - Mapit by mySociaty . Would be amazing if anyone could suggest or point me in the direction for creating a similar functions in rails. I'm especially interested in functions like 'Touching this area' as showed in the mapit.mysociety.org site.
Google maps also show boundaries of an area e.g. google map example Shows boundaries for 'Roath' area. is there anyway retrieve that data from google ?
I also tested a lot of addresses with geocoder, looking up in google. Tried to Geocode from address administrative_area_level_1 2 and 3 as well as in locality or sublocality.
The results were very unreliable. Tried at least 20 addresses from birmigham city - only some of them returned administrative_area_level1,2,3 or locality or sublocality and most of the time it was wrong data.
Another website that is sort of showing ward areas with in a city is www.streetlife.com I think it only works for UK users. basically it takes a postcode from a user and then in their map they show users district and other district around it, which is pretty cool :) Does anyone know how it works ? or how to get something like that working in rails ?
I would really love to discuss this topic in more depth and figure out the best answers for it.

This question at gis.stackexchange is probably of use to you if you wish to use rails. The "touching" feature is fundamentally a PostGIS query, so you could build on top of anything that allowed you to make SQL queries to a PostgreSQL database - GeoDjango (on which MapIt is built) makes this nice, but you could certainly accomplish the same in rails with work.
You won't be able to get those boundaries you see out of Google Maps, I believe, as it's proprietary.
Geocoding is a separate topic - you may want to look at things like OpenStreetMap's Nominatim (MapQuest have a version) or GeoNames, which could supply a dataset you could use with geocoder - Ordnance Survey also publish GB datasets that could be of use.

Related

Rails app for food truck, using twitter to update the google map.

So I am writing a rails application for my friends food truck business.
The functionality that I am trying to create with this specific application is the ability for him to update the google map by posting a Geo-location tag on twitter.
A lot of the ruby gems that deal with google maps seem to be depreciated so I'm a bit lost at the moment. If anyone could just point me in the correct direction I would appreciate it.
I realize that this feature is just a quality of life feature but id like to be able to do it with embedded ruby and not have to break out the JavaScript (ugh). Ideal this kind of automation would be great for this particular type of website because my friend won't always have access to the back-end of the website when he is on the move. (Already able to update a map from an admin backend but its not good enough for a business that moves multiple places in a given day.)
anyways, thanks in advance. (if anyone wants me to post any of my code I will.)
So after reading your question, I thought it would be fun to tinker with the Twitter API again since I haven't used it in a while.
I went ahead and created a sample application for you that basically does what you were asking for. It looks for recent tweets from a user, grabs the latest one, then updates a Google map with a marker on that location.
Keep in mind that this was quickly thrown together, so it's far from perfect. But all the concepts should be there!
Feel free to reach out if you have any questions about the app or anything else. I'm always happy to help.

Google Geocoding API error: over query limit. - Rails

I know this question has been asked but most answers were a few years old and not all for a Ruby on Rails project. In my current project, I am using the Geocode gem (via Ruby on Rails) and anyone is able to search users by their location (which I also use the Carmen gem for country, subregion).
Anyway, I've been receiving this issue lately (Google Geocoding API error: over query limit.). After reading up on it, I see that this is quite common. Most of the resolutions seem to involve caching but others say that it does not work much/well.
I wanted to pose the question to many here and see what various people think is a good resolution. Ideally it would be great to keep the Geocoding gem within the project, but if it is not worth it, please let me know of an alternative. If you know of a resolution to this issue, please let me know too.
Thank you and simply looking to receive feedback for this situation =)
PS: I do not use the Google Maps API. The project is setup so that a user enters their information (using Carmen gem) and typing the cit. The location is geocoded and others can type in a city, state/region to find users within that region.
EDIT
Additional Question: When this limit is met, would that also cause the longitude and latitude value to be nil when a user signs up? Since it is as the limit, it will not geocode the location entered and so it keeps the value at nil? I've had this happen before so I just want to make sure this is why =P
EDIT 2 - ANSWER?
After speaking a bit (in comments below), it seems the best option is to cache the information. With that being said, after researching I see that there are a lot of legalities when it comes to caching with google? Again I do not use the Google Map API so the legal aspect may not be relevant?
Would this be a good solution to implementing the cache (https://github.com/codeforamerica/ohana-api/wiki/Customizing-the-geocoding-configuration)?
Just want to make sure I implement the cache aspect properly =P Thanks!
Joe
ANSWER
So after some research and help from japed (see comments above), I found this documentation (https://github.com/codeforamerica/ohana-api/wiki/Customizing-the-geocoding-configuration) which clearly explained how to setup Redis with Geocoding for caching purposes. It also provided another link with more information to test it in development before deploy.
Thank you!
Joe

Geocoding on the fly vs database lookup

I'm starting a new rails project that integrates closely with Google Maps. When a user searches for a city, I'm trying to decide whether to geocode the address on the fly (using Google's Geocoding API) or to look up the city in a database pre-populated with lat/long. After I have the lat/long I will plot it on Google Maps.
Which do you think would perform better? With the database lookup, the table would have to be pretty large to account for all the cities I would need and I would have to fallback on the geocoding API anyway for any cities that I don't have in my database.
I wasn't sure if there is a common practice to this or not. I don't need a user's specific location, but just a city they are searching for.
The size of the table is no problem, as long as you index on the city name.
Performance of indexed database queries outspeed web API access by far.
An other point is, that you have better controll of the found data. For example, if you find more than one matching city, you can provide a choice of your DB entries, while Google sometimes reports none or some random (or at least unexpected) search result.
This is, why I had to change to a DB search first strategy in one of my project: Google somtimes didn't find my customers addresses but something total different (i.e. small villages with the same name as the expected bigger one)
Why not do both?
Have the address's geocoded information in your database as "Address Cache" and then call the Google Maps Geocode API only if the address doesn't already exist in your database. That's the approach I used in my Google Maps to SugarCRM integration. It works well. BTW, the Google Maps Geocode API is impressively fast, so users rarely notice. Yet, there is a 2,500/day limit on request and it's also throttled to about 10 requests per second. So, considering those limits, I think a combination database/geocode approach is much better in the long run.
https://github.com/jjwdesign/JJWDesign-Google-Maps

Geolocation and getting a city from an input address (Rails)

The app I'm building needs to be able to match up users to events based on the city/town they're in. I'm still relatively new to Rails and completely new to Geolocation and using locations in an app. I'd figured on a design where users have one or many cities, and events would have one city which I'd hoped to extract without specifically asking the user for it, by getting it from the event address entered.
Mostly to provide some outside checking to help get the address entered correctly and consistently, but also to show a map, I installed this jquery address picker (https://github.com/sgruhier/jquery-addresspicker). Unfortunately the data returned by Google doesn't include a city but a "locality" or an "administrative area" that doesn't correlate reliably to city names. The localities being returned are more like what we in my home town would call "suburbs". What I need to procure is a city so I can allow users to search all events in their city rather than just the ones in their suburb.
Can anyone offer advice on how I could go about doing this? Many thanks.
Edit: Should maybe add that I'm wanting to do geocoding client-side so I don't run into problems with Google Maps limits or have to pay for geocoding etc.
There are some gems that provide you with that and may others geo related features, like calculating distances.
Here are the 2 most famous: https://github.com/alexreisner/geocoder and https://github.com/imajes/geokit
In the future I highly recommend you to head to https://www.ruby-toolbox.com/ to see what is available as a gem already and see what is the most popular at the moment.
For raw address info, use Google Maps API Reverse Geocoding which accepts lat/lon inputs and returns street address components. Modern browsers support location awareness (geolocation), with user permission, and will give you a lat/lon that "tends to be close" to where the browser is. That will probably get you a correct city/town in most cases.
The maps API is part of Google's broad suite of API tools -- there are gems that handle any Google API (well, most of them), or check out Google Maps for Rails, which will at the very least give you a good head start on how to use the API.
But if you're looking to validate postal code, this method will come up short, since the location awareness will vary in accuracy depending on browser, device (more accurate for mobile), the connection, population density, network coverage, and so on. Also, calling the
If you can get GPS-accurate lat/lon then it will be much more accurate ... except in some cases like in large cities, a single building will have its own postal code, so a few feet one way or the other might matter.

Proximity searches in Rails

What proximity search options are there for Rails? (Perhaps with pros and cons of each?)
Is a postcode database the way to go?
or using Geocoding with a gem such as Geocoder?
Are there any best practises or gotchas to be aware of?
(Example usage, A Yellow Pages type app where businesses can list, and users can enter their postcode and find businesses that are close to them, or within a radius of specified miles.)
Update: The app is pretty much exactly like the example app above - Businesses can list in the app which is essential a directory (which will have categories for each type of business) and users can go to a category and sort the results by distance (after entering their postcode - so the businesses closest to them, gets shown first). There will be no searching by name or other criteria - it is a simple go to the 'Boxer Dog Breeders' page and sort by distance.
Well the answer depends on what you want to do. If you want simple proximity searches (within a radius and stuff) then the Geocoder gem is more than fine! Now, if you want more advanced search capabilities (polygon, multi-polygon searches etc) I would suggest to go with the PostrgeSQL database and the wonderful PostGIS extension. For use with Rails you should definitely check out the PostGIS adapter for ActiveRecord which comes from the author of a really nice gem called RGeo which uses the superfast libraries GEOS and Proj for the Geospatial calculations.
Otherwise if you find that you need a dedicated search server that has GIS capabilities then you should definitely use ElasticSearch and Ruby has a great gem to aid you with ES called Tire.
Hope I helped!
If you plan to add addational search criteria (eg. name of firm, category) or complex sorting and your DB will grow over 10000 I'm recommend using external search server. For example sphinx search + thinking sphinx.
Here is example of geosearching: http://freelancing-god.github.com/ts/en/geosearching.html
RoR model solutions (like Geocoder) are not very efficient with full text searching.
I don't have experience with Geocoding myself, but Alex Reisner's Geocoder gem looks like the best option, by a mile.
Geocoder is a complete geocoding solution for Ruby. With Rails it adds geocoding (by street or IP address), reverse geocoding (find street address based on given coordinates), and distance queries. It’s as simple as calling geocode on your objects, and then using a scope like Venue.near("Billings, MT").
Checkout the README for a full example on how to use it.

Resources