search nearby places from database [swift] - ios

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)

Related

Proximity Based Search without user location swift

I'm working on an app which utilizes Google Places API in order to find locations based on a users search. I've implemented the search with the help of the UIAutocomplete (Google Places), but unfortunately, it is not location based (until the user provides authorization). I was wondering if there is a way to get the users location through their IP address or otherwise using Swift. I don't need a precise location, the city would be enough.
I've searched for a while and there doesn't seem to be any other way of doing this, so if you know of an API which can return the city the user is currently in, that would be great.
Thanks for all the help,
Vlad
I don't think the system frameworks allow you to get the user's remote IP address anymore. A solution for you might be to use a website like http://mylocation.org/, which shows your IP address and location. Perhaps you can make a request to this website and parse out the HTML that comes back to get the location. Please note, this isn't the most accurate way of getting the user's location and you would be much better off using the CoreLocation framework.

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

Allow users to input the location of an event IOS

I am trying to construct an app for IOS 8 using swift in which users have the ability to post the location of an event, and people within a certain distance have the opportunity to see it based on their current location.
After looking around for awhile, I am getting the notion that this is not possible. I know it is possible if it is based on the user that posts current location (Yik Yak), but I am not if there is a way to let them actually input an address with maps.
Does anyone have a potential answer to this?
Thanks!
You can certainly have a user insert locations and such by importing MapKit.

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/

Locating closest GPS marker from Geonames database

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

Resources