Here's user story:
这是用户故事:
User enters address: Paris, France. Then I would like to display google map center on Paris with one movable marker. Then user point with marker to its exact location and clicks save. Address string and map coordinates are saved to database.
用户输入地址:法国巴黎。然后我想用一个可移动的标记在巴黎显示谷歌地图中心。然后用户使用标记指向其确切位置并单击保存。地址字符串和地图坐标保存到数据库中。
After some search I know I can display google map with variuos gems: cartographer for example. My question is how to get coordinates or how to pass address to cartographer so it centers map in Paris?
经过一些搜索,我知道我可以用variuos gems显示谷歌地图:例如,制图师。我的问题是如何获取坐标或如何将地址传递给制图师,以便将其映射到巴黎?
3 个解决方案
#1
11
I agree, geokit is pretty useful...you can do things like:
我同意,geokit非常有用......你可以做以下事情:
require 'geokit'
include GeoKit::Geocoders
coords = MultiGeocoder.geocode(location)
puts coords.lat
puts coords.lng
Where location is a string location (like an address). It works pretty well.
位置是字符串位置(如地址)。它工作得很好。
You can ALSO reverse geocode, which pulls a string address out of a lat/lng coordinate pair. Pretty spiffy.
你也可以反转地理编码,它从一个lat / lng坐标对中拉出一个字符串地址。漂亮的漂亮。
#2
11
Another geocoder option for Ruby is Geocoder: https://github.com/alexreisner/geocoder
Ruby的另一个地理编码器选项是Geocoder:https://github.com/alexreisner/geocoder
location = Geocoder.search( ... )
location[0].latitude
location[0].longitude
#3
3
I suggest the gem and plugin geokit. It does exactly what you are looking for and more.
我建议宝石和插件geokit。它完全符合您的要求和更多。
#1
11
I agree, geokit is pretty useful...you can do things like:
我同意,geokit非常有用......你可以做以下事情:
require 'geokit'
include GeoKit::Geocoders
coords = MultiGeocoder.geocode(location)
puts coords.lat
puts coords.lng
Where location is a string location (like an address). It works pretty well.
位置是字符串位置(如地址)。它工作得很好。
You can ALSO reverse geocode, which pulls a string address out of a lat/lng coordinate pair. Pretty spiffy.
你也可以反转地理编码,它从一个lat / lng坐标对中拉出一个字符串地址。漂亮的漂亮。
#2
11
Another geocoder option for Ruby is Geocoder: https://github.com/alexreisner/geocoder
Ruby的另一个地理编码器选项是Geocoder:https://github.com/alexreisner/geocoder
location = Geocoder.search( ... )
location[0].latitude
location[0].longitude
#3
3
I suggest the gem and plugin geokit. It does exactly what you are looking for and more.
我建议宝石和插件geokit。它完全符合您的要求和更多。