在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):qpowell/google_places开源软件地址(OpenSource Url):https://github.com/qpowell/google_places开源编程语言(OpenSource Language):Ruby 100.0%开源软件介绍(OpenSource Introduction):¶ ↑Google PlacesThis gem provides a Ruby wrapper around the Google Places API, using HTTParty. At this moment the gem does not support OAuth authentication and will only work with an API key. ¶ ↑Obtaining an API keyTo be able to use this gem, you'll need a Google Places API key. To request an API key, point your browser to developers.google.com/places/web-service/get-api-key and follow the instructions there. ¶ ↑Installing the gemTo use this gem, install it with gem 'google_places' And install it with ¶ ↑Usage¶ ↑The spotEach of the API methods below returns a
However
¶ ↑Retrieving a list of spotsFirst register a new Client: @client = GooglePlaces::Client.new(API_KEY) Then retrieve a list of spots: @client.spots(-33.8670522, 151.1957362) Search by a specific type: @client.spots(-33.8670522, 151.1957362, :types => 'restaurant') Search by multiple types: @client.spots(-33.8670522, 151.1957362, :types => ['restaurant','food']) Search by multiple types but exclude one type: @client.spots(-33.8670522, 151.1957362, :types => ['restaurant','food'], :exclude => 'cafe') Search by multiple types but exclude multiple types: @client.spots(-33.8670522, 151.1957362, :types => ['restaurant','food'], :exclude => ['cafe', 'establishment']) Search by name: @client.spots(-33.8670522, 151.1957362, :name => 'italian') Search by name and type: @client.spots(-33.8670522, 151.1957362, :name => 'italian', :types => 'restaurant') Search in a radius (in meters): @client.spots(-33.8670522, 151.1957362, :radius => 100) Get results in specific language: @client.spots(-33.8670522, 151.1957362, :language => 'en') Get detailed spots (this makes an extra call for each spot and returns a collection of the detailed spots): @client.spots(-33.8670522, 151.1957362, :detail => true) ¶ ↑Retrieving spots based on query@client.spots_by_query('Pizza near Miami Florida') Search by multiple types and exclude multiple types @client.spots_by_query('Pizza near Miami Florida', :types => ['restaurant', 'food'], :exclude => ['cafe', 'establishment']) ¶ ↑Retrieving a collection of spots with complete detailsGoogle limits the details that are returned in any API calls for a collection, so you'll often find that details such as phone numbers are missing in a collection of spots, but are filled in when retrieving a single spot. If you require these extra details to be completed when retrieving a number of results, you can pass in the This option should be used with care, as it adds an additional API call for EACH spot in the collection. E.g. a spots collection of 100 spots will use 101 API calls when the ¶ ↑Retrieving a single spotFirst register a new Client: @client = GooglePlaces::Client.new(API_KEY) Then retrieve the spot: @client.spot('CmRYAAA...upoTH3g') ¶ ↑Retrieving a single photo's urlFirst register a new Client: @client = GooglePlaces::Client.new(API_KEY) Then retrieve the spot: @spot = @client.spot('CmRYAAA...upoTH3g') Then request one of the photos url with a max width: url = @spot.photos[0].fetch_url(800) ¶ ↑Places Autocompletedevelopers.google.com/places/documentation/autocomplete Note: Autocomplete is often used and better suited on client side (browser/javascript). The Autocomplete API is rate limited, so make sure you check the usage limits before deciding on whether to call the API server/client side. developers.google.com/maps/documentation/business/articles/usage_limits ¶ ↑Example usageRegister a new Client: @client = GooglePlaces::Client.new(API_KEY) Then request a prediction based on partial match: @client.predictions_by_input( 'San F', lat: 0.0, lng: 0.0, radius: 20000000, types: 'geocode', language: I18n.locale, ) The response will be an array of predictions. ¶ ↑DevelopmentYou're very welcome to add functionality to this gem. To do so, follow these steps:
Feel free to send me a pull request but please make sure your changes are sufficiently covered by RSpec. ¶ ↑Important NoteConcerning the "You can store this token and use it at any time in future to refresh cached data about this Place,
but the same token is not guaranteed to be returned for any given Place across different searches."
Please be aware that the |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论