Documentation
¶
Overview ¶
Package goplaces provides a Go client for the Google Places API (New).
Index ¶
- Constants
- Variables
- type APIError
- type AuthorAttribution
- type AutocompleteRequest
- type AutocompleteResponse
- type AutocompleteSuggestion
- type Client
- func (c *Client) Autocomplete(ctx context.Context, req AutocompleteRequest) (AutocompleteResponse, error)
- func (c *Client) Details(ctx context.Context, placeID string) (PlaceDetails, error)
- func (c *Client) DetailsWithOptions(ctx context.Context, req DetailsRequest) (PlaceDetails, error)
- func (c *Client) Directions(ctx context.Context, req DirectionsRequest) (DirectionsResponse, error)
- func (c *Client) NearbySearch(ctx context.Context, req NearbySearchRequest) (NearbySearchResponse, error)
- func (c *Client) PhotoMedia(ctx context.Context, req PhotoMediaRequest) (PhotoMediaResponse, error)
- func (c *Client) Resolve(ctx context.Context, req LocationResolveRequest) (LocationResolveResponse, error)
- func (c *Client) Route(ctx context.Context, req RouteRequest) (RouteResponse, error)
- func (c *Client) Search(ctx context.Context, req SearchRequest) (SearchResponse, error)
- type DetailsRequest
- type DirectionsRequest
- type DirectionsResponse
- type DirectionsStep
- type Filters
- type LatLng
- type LocalizedText
- type LocationBias
- type LocationResolveRequest
- type LocationResolveResponse
- type NearbySearchRequest
- type NearbySearchResponse
- type Options
- type Photo
- type PhotoMediaRequest
- type PhotoMediaResponse
- type PlaceDetails
- type PlaceSummary
- type ResolvedLocation
- type Review
- type ReviewVisitDate
- type RouteRequest
- type RouteResponse
- type RouteWaypoint
- type SearchRequest
- type SearchResponse
- type ValidationError
Constants ¶
const DefaultBaseURL = "https://places.googleapis.com/v1"
DefaultBaseURL is the default endpoint for the Places API (New).
Variables ¶
var ErrMissingAPIKey = fmt.Errorf("goplaces: missing api key")
ErrMissingAPIKey indicates a missing API key.
Functions ¶
This section is empty.
Types ¶
type AuthorAttribution ¶
type AuthorAttribution struct {
DisplayName string `json:"display_name,omitempty"`
URI string `json:"uri,omitempty"`
PhotoURI string `json:"photo_uri,omitempty"`
}
AuthorAttribution describes a review author.
type AutocompleteRequest ¶ added in v0.2.0
type AutocompleteRequest struct {
Input string `json:"input"`
SessionToken string `json:"session_token,omitempty"`
Limit int `json:"limit,omitempty"`
Language string `json:"language,omitempty"`
Region string `json:"region,omitempty"`
LocationBias *LocationBias `json:"location_bias,omitempty"`
}
AutocompleteRequest defines input for autocomplete suggestions.
type AutocompleteResponse ¶ added in v0.2.0
type AutocompleteResponse struct {
Suggestions []AutocompleteSuggestion `json:"suggestions"`
}
AutocompleteResponse contains suggestions from autocomplete.
type AutocompleteSuggestion ¶ added in v0.2.0
type AutocompleteSuggestion struct {
Kind string `json:"kind"`
PlaceID string `json:"place_id,omitempty"`
Place string `json:"place,omitempty"`
Text string `json:"text,omitempty"`
MainText string `json:"main_text,omitempty"`
SecondaryText string `json:"secondary_text,omitempty"`
Types []string `json:"types,omitempty"`
DistanceMeters *int `json:"distance_meters,omitempty"`
}
AutocompleteSuggestion is a place or query prediction.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps access to the Google Places API.
func (*Client) Autocomplete ¶ added in v0.2.0
func (c *Client) Autocomplete(ctx context.Context, req AutocompleteRequest) (AutocompleteResponse, error)
Autocomplete returns place and query suggestions for an input string.
func (*Client) DetailsWithOptions ¶
func (c *Client) DetailsWithOptions(ctx context.Context, req DetailsRequest) (PlaceDetails, error)
DetailsWithOptions fetches place details with locale hints.
func (*Client) Directions ¶ added in v0.3.0
func (c *Client) Directions(ctx context.Context, req DirectionsRequest) (DirectionsResponse, error)
Directions fetches directions between two locations using the Routes API.
func (*Client) NearbySearch ¶ added in v0.2.0
func (c *Client) NearbySearch(ctx context.Context, req NearbySearchRequest) (NearbySearchResponse, error)
NearbySearch performs a nearby search around a location restriction.
func (*Client) PhotoMedia ¶ added in v0.2.0
func (c *Client) PhotoMedia(ctx context.Context, req PhotoMediaRequest) (PhotoMediaResponse, error)
PhotoMedia fetches a photo URL for a photo resource name.
func (*Client) Resolve ¶
func (c *Client) Resolve(ctx context.Context, req LocationResolveRequest) (LocationResolveResponse, error)
Resolve converts a free-form location string into candidate places.
func (*Client) Route ¶ added in v0.2.0
func (c *Client) Route(ctx context.Context, req RouteRequest) (RouteResponse, error)
Route searches for places along a route between two locations.
func (*Client) Search ¶
func (c *Client) Search(ctx context.Context, req SearchRequest) (SearchResponse, error)
Search performs a text search with optional filters.
type DetailsRequest ¶
type DetailsRequest struct {
PlaceID string `json:"place_id"`
Language string `json:"language,omitempty"`
Region string `json:"region,omitempty"`
// IncludeReviews requests the reviews field in Place Details.
IncludeReviews bool `json:"include_reviews,omitempty"`
// IncludePhotos requests the photos field in Place Details.
IncludePhotos bool `json:"include_photos,omitempty"`
}
DetailsRequest fetches place details with optional locale hints.
type DirectionsRequest ¶ added in v0.3.0
type DirectionsRequest struct {
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
FromPlaceID string `json:"from_place_id,omitempty"`
ToPlaceID string `json:"to_place_id,omitempty"`
FromLocation *LatLng `json:"from_location,omitempty"`
ToLocation *LatLng `json:"to_location,omitempty"`
Mode string `json:"mode,omitempty"`
Language string `json:"language,omitempty"`
Region string `json:"region,omitempty"`
Units string `json:"units,omitempty"`
}
DirectionsRequest describes a directions query between two locations.
type DirectionsResponse ¶ added in v0.3.0
type DirectionsResponse struct {
Mode string `json:"mode"`
Summary string `json:"summary,omitempty"`
StartAddress string `json:"start_address,omitempty"`
EndAddress string `json:"end_address,omitempty"`
DistanceText string `json:"distance_text,omitempty"`
DistanceMeters int `json:"distance_meters,omitempty"`
DurationText string `json:"duration_text,omitempty"`
DurationSeconds int `json:"duration_seconds,omitempty"`
Warnings []string `json:"warnings,omitempty"`
Steps []DirectionsStep `json:"steps,omitempty"`
}
DirectionsResponse contains a single route summary and steps.
type DirectionsStep ¶ added in v0.3.0
type DirectionsStep struct {
Instruction string `json:"instruction,omitempty"`
DistanceText string `json:"distance_text,omitempty"`
DistanceMeters int `json:"distance_meters,omitempty"`
DurationText string `json:"duration_text,omitempty"`
DurationSeconds int `json:"duration_seconds,omitempty"`
TravelMode string `json:"travel_mode,omitempty"`
Maneuver string `json:"maneuver,omitempty"`
}
DirectionsStep is a single navigation step.
type Filters ¶
type Filters struct {
Keyword string `json:"keyword,omitempty"`
Types []string `json:"types,omitempty"`
OpenNow *bool `json:"open_now,omitempty"`
MinRating *float64 `json:"min_rating,omitempty"`
PriceLevels []int `json:"price_levels,omitempty"`
}
Filters are optional search refinements.
type LocalizedText ¶
type LocalizedText struct {
Text string `json:"text,omitempty"`
LanguageCode string `json:"language_code,omitempty"`
}
LocalizedText is a text value with an optional language code.
type LocationBias ¶
type LocationBias struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
RadiusM float64 `json:"radius_m"`
}
LocationBias limits search results to a circular area.
type LocationResolveRequest ¶
type LocationResolveRequest struct {
LocationText string `json:"location_text"`
Limit int `json:"limit,omitempty"`
Language string `json:"language,omitempty"`
Region string `json:"region,omitempty"`
}
LocationResolveRequest resolves a text location into place candidates.
type LocationResolveResponse ¶
type LocationResolveResponse struct {
Results []ResolvedLocation `json:"results"`
}
LocationResolveResponse contains resolved locations.
type NearbySearchRequest ¶ added in v0.2.0
type NearbySearchRequest struct {
LocationRestriction *LocationBias `json:"location_restriction,omitempty"`
Limit int `json:"limit,omitempty"`
IncludedTypes []string `json:"included_types,omitempty"`
ExcludedTypes []string `json:"excluded_types,omitempty"`
Language string `json:"language,omitempty"`
Region string `json:"region,omitempty"`
}
NearbySearchRequest defines a nearby search query.
type NearbySearchResponse ¶ added in v0.2.0
type NearbySearchResponse struct {
Results []PlaceSummary `json:"results"`
NextPageToken string `json:"next_page_token,omitempty"`
}
NearbySearchResponse contains nearby search results.
type Options ¶
type Options struct {
APIKey string
BaseURL string
RoutesBaseURL string
DirectionsBaseURL string
HTTPClient *http.Client
Timeout time.Duration
}
Options configures the Places client.
type Photo ¶ added in v0.2.0
type Photo struct {
Name string `json:"name,omitempty"`
WidthPx int `json:"width_px,omitempty"`
HeightPx int `json:"height_px,omitempty"`
AuthorAttributions []AuthorAttribution `json:"author_attributions,omitempty"`
}
Photo describes photo metadata for a place.
type PhotoMediaRequest ¶ added in v0.2.0
type PhotoMediaRequest struct {
Name string `json:"name"`
MaxWidthPx int `json:"max_width_px,omitempty"`
MaxHeightPx int `json:"max_height_px,omitempty"`
}
PhotoMediaRequest fetches a photo URL from a photo resource name.
type PhotoMediaResponse ¶ added in v0.2.0
type PhotoMediaResponse struct {
Name string `json:"name,omitempty"`
PhotoURI string `json:"photo_uri,omitempty"`
}
PhotoMediaResponse contains the photo URL for a photo name.
type PlaceDetails ¶
type PlaceDetails struct {
PlaceID string `json:"place_id"`
Name string `json:"name,omitempty"`
Address string `json:"address,omitempty"`
Location *LatLng `json:"location,omitempty"`
Rating *float64 `json:"rating,omitempty"`
UserRatingCount *int `json:"user_rating_count,omitempty"`
PriceLevel *int `json:"price_level,omitempty"`
Types []string `json:"types,omitempty"`
Phone string `json:"phone,omitempty"`
Website string `json:"website,omitempty"`
Hours []string `json:"hours,omitempty"`
OpenNow *bool `json:"open_now,omitempty"`
Reviews []Review `json:"reviews,omitempty"`
Photos []Photo `json:"photos,omitempty"`
}
PlaceDetails is a detailed view of a place.
type PlaceSummary ¶
type PlaceSummary struct {
PlaceID string `json:"place_id"`
Name string `json:"name,omitempty"`
Address string `json:"address,omitempty"`
Location *LatLng `json:"location,omitempty"`
Rating *float64 `json:"rating,omitempty"`
UserRatingCount *int `json:"user_rating_count,omitempty"`
PriceLevel *int `json:"price_level,omitempty"`
Types []string `json:"types,omitempty"`
OpenNow *bool `json:"open_now,omitempty"`
}
PlaceSummary is a compact view of a place.
type ResolvedLocation ¶
type ResolvedLocation struct {
PlaceID string `json:"place_id"`
Name string `json:"name,omitempty"`
Address string `json:"address,omitempty"`
Location *LatLng `json:"location,omitempty"`
Types []string `json:"types,omitempty"`
}
ResolvedLocation is a place candidate for a location string.
type Review ¶
type Review struct {
Name string `json:"name,omitempty"`
RelativePublishTimeDescription string `json:"relative_publish_time_description,omitempty"`
Text *LocalizedText `json:"text,omitempty"`
OriginalText *LocalizedText `json:"original_text,omitempty"`
Rating *float64 `json:"rating,omitempty"`
Author *AuthorAttribution `json:"author,omitempty"`
PublishTime string `json:"publish_time,omitempty"`
FlagContentURI string `json:"flag_content_uri,omitempty"`
GoogleMapsURI string `json:"google_maps_uri,omitempty"`
VisitDate *ReviewVisitDate `json:"visit_date,omitempty"`
}
Review represents a user review of a place.
type ReviewVisitDate ¶
type ReviewVisitDate struct {
Year int `json:"year,omitempty"`
Month int `json:"month,omitempty"`
Day int `json:"day,omitempty"`
}
ReviewVisitDate describes the date a reviewer visited a place.
type RouteRequest ¶ added in v0.2.0
type RouteRequest struct {
Query string `json:"query"`
From string `json:"from"`
To string `json:"to"`
Mode string `json:"mode,omitempty"`
RadiusM float64 `json:"radius_m,omitempty"`
MaxWaypoints int `json:"max_waypoints,omitempty"`
Limit int `json:"limit,omitempty"`
Language string `json:"language,omitempty"`
Region string `json:"region,omitempty"`
}
RouteRequest describes a query to search along a route.
type RouteResponse ¶ added in v0.2.0
type RouteResponse struct {
Waypoints []RouteWaypoint `json:"waypoints"`
}
RouteResponse contains sampled waypoints with search results.
type RouteWaypoint ¶ added in v0.2.0
type RouteWaypoint struct {
Location LatLng `json:"location"`
Results []PlaceSummary `json:"results"`
}
RouteWaypoint ties a sampled route location to search results.
type SearchRequest ¶
type SearchRequest struct {
Query string `json:"query"`
Filters *Filters `json:"filters,omitempty"`
LocationBias *LocationBias `json:"location_bias,omitempty"`
Limit int `json:"limit,omitempty"`
PageToken string `json:"page_token,omitempty"`
Language string `json:"language,omitempty"`
Region string `json:"region,omitempty"`
}
SearchRequest defines a text search with optional filters.
type SearchResponse ¶
type SearchResponse struct {
Results []PlaceSummary `json:"results"`
NextPageToken string `json:"next_page_token,omitempty"`
}
SearchResponse contains a list of places and optional pagination token.
type ValidationError ¶
ValidationError describes an invalid request payload.
func (ValidationError) Error ¶
func (e ValidationError) Error() string