• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

joshcrews/google-directions-ruby: Ruby-wrapper for Google Directions API. Can r ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

joshcrews/google-directions-ruby

开源软件地址(OpenSource Url):

https://github.com/joshcrews/google-directions-ruby

开源编程语言(OpenSource Language):

Ruby 100.0%

开源软件介绍(OpenSource Introduction):

Usage

directions = GoogleDirections.new(origin, destination)

where origin and destination are strings of addresses or places that Google can find an address for. Example: “816 Meridian St., 37207”

Get drive time or distance of whole trip


drive_time_in_minutes = directions.drive_time_in_minutes
distance_in_miles = directions.distance_in_miles

Get the XML Google returns with every turn, or the API call URL


xml = directions.xml
xml_call = directions.xml_call

Error situations

status: NOT_FOUND

If Google can’t recognize your places, the distance_in_miles and drive_time_in_minutes will each return 0. You can call

directions.status
and it should return “NOT_FOUND” (directions.status will also return any other Google API call statuses)

status: OVER_QUERY_LIMIT

If Google thinks you’ve hit their API too many times in day, or too rapidly, for your given IP address and API key; they might return OVER_QUERY_LIMIT. In this case distance_in_miles and drive_time_in_minutes will each return 0. You can call

directions.status
and it should return “OVER_QUERY_LIMIT”

Installation

gem

rails 3.0/4.0

  1. gem ‘google_directions’ in your Gemfile
  2. bundle install
    from command line

Compatibility

Tested on Rails 2.3.8
Tested on Rails 4.0.1

Google maps API key

You’ll need a Google Map API key

http://code.google.com/apis/maps/signup.html

Include it as the constant GOOGLE_MAPS_API_KEY in an app configuration file (environment.rb, config/initializers/api_keys.rb)

Need turn-by-turn directions?

Not yet included in this gem, but you can do it with nokogiri to parse the XML that comes back when you do

GoogleDirections.new(origin, destination).xml

And then nokogiri can cycle through each and you can pick out what you need.

License

Anyone can use this code in any way.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap