Rails How to get latitude and longitude from a string address and place it on a Google map?

Here is the user story:

The user enters the address: Paris, France. Then I would like to display the google map center in Paris with one moving marker. The user then points the marker to the exact location and clicks it. The address bar and map coordinates are stored in the database.

After some searching, I know that I can display a google map with variuos gems: for example, a cartographer. My question is: how to get the coordinates or how to pass the address to the cartographer so that he centers the map in Paris?

+4
source share
3 answers

I agree geokit is very useful ... you can do things like:

require 'geokit' include GeoKit::Geocoders coords = MultiGeocoder.geocode(location) puts coords.lat puts coords.lng 

Where location is a string location (e.g. address). It works very well.

You can also turn off the geocode that pulls the string address from the lat / lng coordinate pair. Pretty spiffy.

+11
source

Another geocoding option for Ruby is Geocoder: https://github.com/alexreisner/geocoder

  location = Geocoder.search( ... ) location[0].latitude location[0].longitude 
+11
source

I offer a gem and a geokit plugin. He does exactly what you are looking for and much more.

+3
source

Source: https://habr.com/ru/post/1338296/


All Articles