Locating closest GPS marker from Geonames database - geolocation

I am developing an Android application that uses the geonames.org database. I only use the city/populated place category and their corresponding coordinates as provided by geonames.
I want the user to be able to provide his/her GPS coordinates and get a result back with the closest cities/populated places and their coordinates.
Even if the user is in a city I want that city's coordinates to be displayed along with the more distant ones.
Can this be done without the help of google or a web service? I might host the world city geolocations on my own server.
Thanks!

Since posting this I have found the answer to my own question. MongoDB supports geospatial indexing. Make sure that the longitude and latitude field is saved in one string and point the geospatial index to your loc: field. You can then perform queries with a bounding box to find closest locations within a certain radius for example. More about MongoDB geospatial indexing can be found here: http://www.mongodb.org/display/DOCS/Geospatial+Indexing

Related

Tools for estimating nearby locations without calling external API (i.e Google Maps)

In my rails application i have some model Location that holds the address and corresponding latitude and longitude.
At the main page, user can search for a location from which he wants to find the nearest places in location table.
I use JavaScript Google API for geocoding on the client side. Since the limit per user is 25000 req/day i guess i do not need to worry about it cause no one will want to search for a location so many times. I use Ajax for sending geocoded latitude and longitude from client to the server.
Now i'm on the sever side and have a reference point and table of locations. But at this moment, i guess i cannot use geocoder gem which use Google API for estimating some nearby locations, cause from the server side there is a limit of 2500 requests per day and i expect to exceed it(don't want to pay either).
What tool can i use to easily return some nearby locations without calling external API? I know that there are other API's but all of them have either limitations or obligations and since it's more like mathematical calculation i can't see the reason to play around with API at this point.
Assuming that you're using a relational database, you can use ElasticSearch to index your Locations and search through them using Geo Distance Range Query.
Other similar option would be use a Mongo collection and take advantage of the Mongo's $near operator.
Edit:
There're some questions related to your question which can be useful if you're using MySQL/PostgreSQL:
Find closest 10 cities with MySQL using latitude and longitude?
postgres longitude longitude query

search nearby places from database [swift]

I am developing an app which allows users to search nearby place according to the radius provided by the user. I have some places stored in a realm database with the latitude and longitude of that place. I am able to get the users current latitude and longitude but i don't know how to implement the logic to present the user with places that are closest to him. I can calculate the distance between users current location and a particular location using CLLocationDistance = currentlocation.distanceFromLocation(destinationLocation).
Please point me in the right direction or provide me with a sample code.
If it's not possible with Realm then let me know which database solution is the best option.
This isn't currently possible in native Realm queries, but it's something that's actively being worked on! (see https://github.com/realm/realm-cocoa/pull/2199 for a current pull request)

Ruby on Rails and gmap location

I come here to ask you some informations or maybe help to try to do what i want.
Here it's what i want to realize:
I have a website and on it i have some places in database (with lattitude and longitude saved). I want allow users, when they click on a button, display a map with a marker on their actual position and others markers who will represent the places from the database near them.
I found some tools like google map API v3. With it i can show the user position but i don't know how i can display the position of the places store in my database.
If you have any ideas or examples.
Thank you.
(PS: Sorry for my english)
I built a similar app with Spring and Java. What you'll have to do is create Placemark JS objects and pass them to the Google Maps API. You can also pass a map size to determine the scope of the map returned to the user.
In order to determine nearby locations, simply build some ruby/rails code to limit the distance of locations from the user location.
Get user location
Determine which locations to show on map within your rails app
Pass desired placemarks to Google Maps (This can be found in API docs which are great)
Display the map returned by Google Maps on a view.
I think you could use geocoder gem for that:
http://www.rubygeocoder.com/

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.

Resources