User clicks on the 'locate me' button
The lat long is populated using HTML5 navigator.geolocation feature
I need to retrieve the county name now
I would also like to avoid Google Maps Geocode API as there are usage limits & I'm already using it for some other purpose
You can use a Reverse Geocoding service like OSM or Photon - live demo.
Related
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
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/
I am using MaxMind GeoIP2 database to determine client's location (longitude, latitude, city, country) based on IP address.
For that I'm using Python library geoip2 and local GeoLite2-City.mmdb database.
In order to get more precise result I want to use HTML5 geolocation in addition which returns only coordinates of the client.
I want to use the already existing MaxMind local database to get the country and city based on the coordinates from HTML5 method.
Is it possible and how?
You might want to check the services they provide (I did not see them having what you are looking for), and then maybe contecting their support for more assistance.
Anyways, you could easily use any Reverce Geocoding service which provides REST interface for determining the country (and actuall more accurate address), thus I would suggest you reconsider the requirements on utilizing the original provider for the purpose.
If for some reason you need to have a certain Geo-location for all users in same city, then after reverce geocoding the city & country, use those values (without any actual street address) with geocoding service to get the 'center' of the city.
The app that I am currently working on has to do this kind of features.
1.User input "Address" and then there will be autocomplete (suggestion for that address)
2. After user hits search button . The MKMapkit has to bring user to that 'Address' and zoom region to that
I can do the #1 by using Google Autocomplete API and using this module TRAutocompleteView
Now ,I'm trying to figure to do #2 feature. I thought I can use Address result from google API to convert into lat,long by CLPlacemark but I tested the concept with this module which use CLPlacemark to convert address string
SPGooglePlacesAutocomplete
I found out that 20-30% of the address string can't be convert using CLPlacemark .It happes to be "Location not found" .And that happens mostly when you search in foreign language (I tried Thai language "
Are any other option for me implement these 2 features ? My app will be like YELP which has to search some result within specific region . Or can I use another way to do the address suggestion beside Google Autocomplete API ?
Changing MapKit to Google Map SDK can be one of the solution.But I want that to be last choice because it might be expensive if I exceed the daily limit
Thanks in advance
Just as a FYI, it is against the Google Terms of Service to use the Google Places Autocomplete with a non Google Map.
This is an obvious side effect of getting an address from Google and then asking Apple's API to turn those addresses into coordinates. Google will give you an address based on the data it has and the formatting style it wants, these will not always directly translate into Apple's data and format. If you want it to be properly reliable you need to stick with one set of services, Google or Apple, or a third party. It might be expensive if you exceed the daily limit but wouldn't that mean you're selling lots of copies of your app and such is the cost of doing business.
In ruby on rails what is the general approach for displaying markers of user entered addresses in a google map?
Should I call the geocoding service for every address when the map is loaded or should I call it when the address is saved and then display all coordinates?
I guess the answer is to call the geocode on save. Otherwise I'll go over the 2500 call/day limit for google maps geocoding service
You should definitely geocode the address when the user provides you with one, and then save the received latLngs in your database. This way saves the amount of geocoding requests.