Categorygithub.com/0987363/google-maps-services-go
modulepackage
1.4.0-fix2
Repository: https://github.com/0987363/google-maps-services-go.git
Documentation: pkg.go.dev

# README

Go Client for Google Maps Services

Build Status GoDoc

Description

Use Go? Want to geocode something? Looking for directions? Maybe matrices of directions? This library brings the Google Maps API Web Services to your Go application.

The Go Client for Google Maps Services is a Go Client library for the following Google Maps APIs:

Keep in mind that the same terms and conditions apply to usage of the APIs when they're accessed through this library.

Support

This library is community supported. We're comfortable enough with the stability and features of the library that we want you to build real production applications on it. We will try to support, through Stack Overflow, the public and protected surface of the library and maintain backwards compatibility in the future; however, while the library is in version 0.x, we reserve the right to make backwards-incompatible changes. If we do remove some functionality (typically because better functionality exists or if the feature proved infeasible), our intention is to deprecate and give developers a year to update their code.

If you find a bug, or have a feature suggestion, please log an issue. If you'd like to contribute, please read How to Contribute.

Requirements

  • Go 1.7 or later.
  • A Google Maps API key.

API keys

Each Google Maps Web Service request requires an API key or client ID. API keys are freely available with a Google Account at Google APIs Console. The type of API key you need is a Server key.

To get an API key:

  1. Visit Google APIs Console and log in with a Google Account.
  2. Select one of your existing projects, or create a new project.
  3. Enable the API(s) you want to use. The Go Client for Google Maps Services accesses the following APIs:
    • Directions API
    • Distance Matrix API
    • Elevation API
    • Geocoding API
    • Places API
    • Roads API
    • Time Zone API
    • Maps Static API
  4. Create a new Server key.
  5. If you'd like to restrict requests to a specific IP address, do so now.

For guided help, follow the instructions for the Directions API. You only need one API key, but remember to enable all the APIs you need. For even more information, see the guide to API keys.

Important: This key should be kept secret on your server.

Installation

To install the Go Client for Google Maps Services, please execute the following go get command.

go get github.com/0987363/google-maps-services-go

Developer Documentation

View the reference documentation

Additional documentation for the included web services is available at developers.google.com/maps and developers.google.com/places.

Usage

Sample usage of the Directions API with an API key:

package main

import (
	"context"
	"log"

	"github.com/kr/pretty"
	"github.com/0987363/google-maps-services-go"
)

func main() {
	c, err := maps.NewClient(maps.WithAPIKey("Insert-API-Key-Here"))
	if err != nil {
		log.Fatalf("fatal error: %s", err)
	}
	r := &maps.DirectionsRequest{
		Origin:      "Sydney",
		Destination: "Perth",
	}
	route, _, err := c.Directions(context.Background(), r)
	if err != nil {
		log.Fatalf("fatal error: %s", err)
	}

	pretty.Println(route)
}

Below is the same example, using client ID and client secret (digital signature) for authentication. This code assumes you have previously loaded the clientID and clientSecret variables with appropriate values.

For a guide on how to generate the clientSecret (digital signature), see the documentation for the API you're using. For example, see the guide for the Directions API.

package main

import (
	"context"
	"log"

	"github.com/kr/pretty"
	"github.com/0987363/google-maps-services-go"
)

func main() {
	c, err := maps.NewClient(maps.WithClientIDAndSignature("Client ID", "Client Secret"))
	if err != nil {
		log.Fatalf("fatal error: %s", err)
	}
	r := &maps.DirectionsRequest{
		Origin:      "Sydney",
		Destination: "Perth",
	}
	route, _, err := c.Directions(context.Background(), r)
	if err != nil {
		log.Fatalf("fatal error: %s", err)
	}

	pretty.Println(route)
}

Features

Rate limiting

Never sleep between requests again! By default, requests are sent at the expected rate limits for each web service, typically 50 queries per second for free users. If you want to speed up or slow down requests, you can do that too, using maps.NewClient(maps.WithAPIKey(apiKey), maps.WithRateLimit(qps)).

Client IDs

Google Maps APIs Premium Plan customers can use their client ID and secret to authenticate, instead of an API key.

Native types

Native objects for each of the API responses.

Monitoring

It's possible to get metrics for status counts and latency histograms for monitoring. Use maps.WithMetricReporter(metrics.OpenCensusReporter{}) to log metrics to OpenCensus, and metrics.RegisterViews() to make the metrics available to be exported. OpenCensus can export these metrics to a variety of monitoring services. You can also implement your own metric reporter instead of using the provided one.

# Packages

No description provided by the author
No description provided by the author

# Functions

DecodePolyline converts a polyline encoded string to an array of LatLng objects.
Encode returns a new encoded Polyline from the given path.
ExperienceIdContext injects the experienceIds in the context, from where they will be pull out in the post/get handlers.
ExperienceIdFromContext returns experienceIds from context if presented.
NewClient constructs a new Client which can make requests to the Google Maps WebService APIs.
NewPlaceAutocompleteSessionToken constructs a new Place Autocomplete session token.
ParseAutocompletePlaceType will parse a string representation of a AutocompletePlaceTypes.
ParseFindPlaceFromTextLocationBiasType will parse a string to a FindPlaceFromTextLocationBiasType.
ParseLatLng will parse a string representation of a Lat,Lng pair.
ParseLatLngList will parse a string of | separated Lat,Lng pairs.
ParsePlaceDetailsFieldMask will parse a string representation of PlaceDetailsFieldMask.
ParsePlaceSearchFieldMask will parse a string representation of PlaceSearchFieldMask.
ParsePlaceType will parse a string representation of a PlaceType.
WithAPIKey configures a Maps API client with an API Key.
WithAPIKeyAndSignature configures a Maps API client with an API Key and signature.
WithBaseURL configures a Maps API client with a custom base url.
WithChannel configures a Maps API client with a Channel.
WithClientIDAndSignature configures a Maps API client for a Maps for Work application.
WithExperienceId configures the client with an initial experience id that can be changed with the `setExperienceId` method.
WithHTTPClient configures a Maps API client with a http.Client to make requests over.
No description provided by the author
WithRateLimit configures the rate limit for back end requests.

# Constants

https://developers.google.com/places/web-service/autocomplete#place_types.
https://developers.google.com/places/web-service/autocomplete#place_types.
https://developers.google.com/places/web-service/autocomplete#place_types.
https://developers.google.com/places/web-service/autocomplete#place_types.
https://developers.google.com/places/web-service/autocomplete#place_types.
Features to avoid.
Features to avoid.
Features to avoid.
Bottom Marker anchor position.
Bottomleft Marker anchor position.
Bottomright Marker anchor position.
Center Marker anchor position.
ComponentAdministrativeArea matches all the administrative_area levels.
ComponentCountry matches a country name or a two letter ISO 3166-1 country code.
ComponentLocality matches against both locality and sublocality types.
ComponentPostalCode matches postal_code and postal_code_prefix.
ComponentRoute matches long or short name of a route.
No description provided by the author
The types of FindPlaceFromText Input Types.
The types of FindPlaceFromText Input Types.
The types of FindPlaceFromTextLocationBiasType.
The types of FindPlaceFromTextLocationBiasType.
The types of FindPlaceFromTextLocationBiasType.
The types of FindPlaceFromTextLocationBiasType.
GeocodeAccuracyApproximate restricts the results to those that are characterized as approximate.
GeocodeAccuracyGeometricCenter restricts the results to geometric centers of a location such as a polyline or polygon.
GeocodeAccuracyRangeInterpolated restricts the results to those that reflect an approximation interpolated between two precise points.
GeocodeAccuracyRooftop restricts the results to addresses for which Google has location information accurate down to street address precision.
GIF specifies the GIF format.
Hybrid specifies a hybrid of the satellite and roadmap image, showing a transparent layer of major streets and place names on the satellite image.
JPG specifies the JPEG compression format.
JPGBaseline specifies a non-progressive JPEG compression format.
Left Marker anchor position.
Mid Marker size.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Details Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
The individual Place Search Field Masks.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
Place Types for the Places API.
PNG32 specifies the 32-bit PNG format.
PNG8 or png (default) specifies the 8-bit PNG format.
Price Levels for the Places API.
Price Levels for the Places API.
Price Levels for the Places API.
Price Levels for the Places API.
Price Levels for the Places API.
Allowed radio types.
Allowed radio types.
Allowed radio types.
Allowed radio types.
RankBy options for Places Search.
RankBy options for Places Search.
Right Marker anchor position.
RoadMap (default) specifies a standard roadmap image, as is normally shown on the Google Maps website.
Satellite specifies a satellite image.
Small Marker size.
SpeedLimitKPH is for requesting speed limits in Kilometers Per Hour.
SpeedLimitMPH is for requesting speed limits in Miles Per Hour.
Terrain specifies a physical relief map image, showing terrain and vegetation.
Tiny Marker size.
Top Marker anchor position.
Topleft Marker anchor position.
Topright Marker anchor position.
Traffic prediction model when requesting future directions.
Traffic prediction model when requesting future directions.
Traffic prediction model when requesting future directions.
Transit mode of directions or distance matrix request.
Transit mode of directions or distance matrix request.
Transit mode of directions or distance matrix request.
Transit mode of directions or distance matrix request.
Transit mode of directions or distance matrix request.
Transit Routing preferences for transit mode requests.
Transit Routing preferences for transit mode requests.
Travel mode preferences.
Travel mode preferences.
Travel mode preferences.
Travel mode preferences.
Units to use on human readable distances.
Units to use on human readable distances.

# Structs

AddressComponent is a part of an address.
AddressGeometry is the location of a an address.
AddressPlusCode (see https://en.wikipedia.org/wiki/Open_Location_Code and https://plus.codes/) is an encoded location reference, derived from latitude and longitude coordinates, that represents an area: 1/8000th of a degree by 1/8000th of a degree (about 14m x 14m at the equator) or smaller.
AutocompleteMatchedSubstring describes the location of the entered term in the prediction result text, so that the term can be highlighted if desired.
AutocompletePrediction represents a single Query Autocomplete result returned from the Google Places API Web Service.
AutocompleteResponse is a response to a Query Autocomplete request.
AutocompleteStructuredFormatting contains the main and secondary text of an autocomplete prediction.
AutocompleteTermOffset identifies each section of the returned description (a section of the description is generally terminated with a comma).
CellTower is a cell tower object for localisation requests.
Client may be used to make requests to the Google Maps WebService APIs.
CustomIcon replace the default Map Pin.
DirectionsRequest is the functional options struct for directions.Get.
Distance is the API representation for a distance between two points.
DistanceMatrixElement is the travel distance and time for a pair of origin and destination.
DistanceMatrixElementsRow is a row of distance elements.
DistanceMatrixRequest is the request struct for Distance Matrix APi.
DistanceMatrixResponse represents a Distance Matrix API response.
ElevationRequest is the request structure for Elevation API.
ElevationResult is a single elevation at a specific location.
Fare represents the total fare for a route.
FindPlaceFromTextRequest is the options struct for Find Place From Text API.
FindPlaceFromTextResponse is a response to the Find Place From Text request.
GeocodedWaypoint represents the geocoded point for origin, supplied waypoints, or destination for a requested direction request.
GeocodingRequest is the request structure for Geocoding API.
GeocodingResult is a single geocoded address.
GeolocationError is an error object reporting a request error.
GeolocationRequest is the request structure for Geolocation API All fields are optional.
GeolocationResult is an approximate location and accuracy.
LatLng represents a location on the Earth.
LatLngBounds represents a bounded square area on the Earth.
Leg represents a single leg of a route.
Marker is a Map pin.
NearbySearchRequest is the functional options struct for NearbySearch.
NearestRoadsRequest is the request structure for the Nearest Roads API.
NearestRoadsResponse is an array of snapped points.
OpeningHours describes the opening hours for a Place Details result.
OpeningHoursOpenClose describes when the place is open.
OpeningHoursPeriod is a single OpeningHours day describing when the place opens and closes.
Path defines a single path of two or more connected points to overlay on the image at specified locations.
Photo describes a photo available with a Search Result.
PlaceAutocompleteRequest is the functional options struct for Place Autocomplete.
PlaceDetailsRequest is the functional options struct for PlaceDetails.
PlaceDetailsResult is an individual Places API Place Details result.
PlaceEditorialSummary contains a summary of the place.
PlacePhotoRequest is the functional options struct for Places Photo API.
PlacePhotoResponse is a response to the Place Photo request.
PlaceReview is a review of a Place.
PlaceReviewAspect provides a rating of a single attribute of the establishment.
PlacesSearchResponse is the response to a Places API Search request.
PlacesSearchResult is an individual Places API search result.
Polyline represents a list of lat,lng points encoded as a byte array.
QueryAutocompleteRequest is the functional options struct for Query Autocomplete.
Route represents a single route between an origin and a destination.
SnappedPoint is the original path point snapped to a road.
SnapToRoadRequest is the request structure for the Roads Snap to Road API.
SnapToRoadResponse is an array of snapped points.
SpeedLimit is the speed limit for a PlaceID.
SpeedLimitsRequest is the request structure for the Roads Speed Limits API.
SpeedLimitsResponse is an array of snapped points and an array of speed limits.
StaticMapRequest is the functional options struct for staticMap.Get.
Step represents a single step of a leg.
TextSearchRequest is the functional options struct for TextSearch.
TimezoneRequest is the request structure for Timezone API.
TimezoneResult is a single timezone result.
TransitAgency contains information about the operator of the line.
TransitDetails contains additional information about the transit stop, transit line and transit agency.
TransitLine contains information about the transit line used in this step.
TransitLineVehicle contains the type of vehicle used on this line.
TransitStop contains information about the stop/station for this part of the trip.
ViaWaypoint handles waypoints.
WiFiAccessPoint is a WiFi access point object for localisation requests.

# Type aliases

Anchor sets how the icon is placed in relation to the specified markers locations.
AutocompletePlaceType restricts Place Autocomplete API to the results to places matching the specified type.
Avoid is for specifying routes that avoid certain features.
ClientOption is the type of constructor options for NewClient(...).
Component specifies a key for the parts of a structured address.
FindPlaceFromTextInputType is the different types of inputs.
FindPlaceFromTextLocationBiasType is the type of location bias for this request.
Format defines the format of the resulting image.
GeocodeAccuracy is the type of a location result from the Geocoding API.
MapType (optional) defines the type of map to construct.
MarkerSize specifies the size of marker from the set {tiny, mid, small}.
Mode is for specifying travel mode.
PlaceAutocompleteSessionToken is a session token for Place Autocomplete.
PlaceDetailsFieldMask allows you to specify which fields are to be returned with a place details request.
PlaceSearchFieldMask allows you to specify which fields are to be returned with a place search request.
PlaceType restricts Place API search to the results to places matching the specified type.
PriceLevel is the Price Levels for Places API.
RadioType defines mobile radio types.
RankBy specifies the order in which results are listed.
TrafficModel specifies traffic prediction model when requesting future directions.
TransitMode is for specifying a transit mode for a request.
TransitRoutingPreference biases which routes are returned.
Units specifies which units system to return human readable results in.