mirror of
https://github.com/imjasonh/staticmaps
synced 2026-07-08 10:55:03 +00:00
Add doc comments for Distance Matrix API methods
This commit is contained in:
parent
e9e7597dd0
commit
9deaf93c7f
1 changed files with 55 additions and 10 deletions
65
distance.go
65
distance.go
|
|
@ -6,6 +6,9 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// DistanceMatrix requests travel distance and time for a matrix of origins and destinations.
|
||||
//
|
||||
// See https://developers.google.com/maps/documentation/distancematrix/
|
||||
func (c Client) DistanceMatrix(orig, dest []Location, opts *DistanceMatrixOpts) (*DistanceMatrixResult, error) {
|
||||
var d distanceResponse
|
||||
if err := c.doDecode(baseURL+distancematrix(orig, dest, opts), &d); err != nil {
|
||||
|
|
@ -25,24 +28,50 @@ func distancematrix(orig, dest []Location, opts *DistanceMatrixOpts) string {
|
|||
return "distancematrix/json?" + p.Encode()
|
||||
}
|
||||
|
||||
// DistanceMatrixOpts defines options for DistanceMatrix requsts.
|
||||
type DistanceMatrixOpts struct {
|
||||
Language, Units string
|
||||
Mode, Avoid *string
|
||||
DepartureTime time.Time
|
||||
// The language in which to return results.
|
||||
//
|
||||
// See https://developers.google.com/maps/faq#languagesupport
|
||||
Language string
|
||||
|
||||
// Specifies the unit system to use when displaying results.
|
||||
//
|
||||
// Accepted values are UnitMetric and UnitImperial.
|
||||
//
|
||||
// See https://developers.google.com/maps/documentation/distancematrix/#unit_systems
|
||||
Units string
|
||||
|
||||
// Specifies the mode of transport to use when calculating directions.
|
||||
//
|
||||
// Accepted values are ModeDriving (the default), ModeWalking and ModeBicycling.
|
||||
Mode string
|
||||
|
||||
// Indicates that the calculated route(s) should avoid the indicated features.
|
||||
//
|
||||
// Accepted values are AvoidTolls, AvoidHighways or AvoidFerries
|
||||
//
|
||||
// See https://developers.google.com/maps/documentation/distancematrix/#Restrictions
|
||||
Avoid string
|
||||
|
||||
// Specifies the desired time of departure.
|
||||
//
|
||||
// The departure time can be specified for Google Maps API for Work clients to receive trip duration considering current traffic conditions.
|
||||
DepartureTime time.Time
|
||||
}
|
||||
|
||||
func (o *DistanceMatrixOpts) update(p url.Values) {
|
||||
if o == nil {
|
||||
return
|
||||
}
|
||||
if o.Mode != nil {
|
||||
p.Set("mode", *o.Mode)
|
||||
if o.Mode != "" {
|
||||
p.Set("mode", o.Mode)
|
||||
}
|
||||
if o.Language != "" {
|
||||
p.Set("language", o.Language)
|
||||
}
|
||||
if o.Avoid != nil {
|
||||
p.Set("avoid", *o.Avoid)
|
||||
if o.Avoid != "" {
|
||||
p.Set("avoid", o.Avoid)
|
||||
}
|
||||
if o.Units != "" {
|
||||
p.Set("units", o.Units)
|
||||
|
|
@ -57,13 +86,29 @@ type distanceResponse struct {
|
|||
DistanceMatrixResult
|
||||
}
|
||||
|
||||
// DistanceMatrixResult describes the matrix of distances between the requested origins and destinations.
|
||||
type DistanceMatrixResult struct {
|
||||
OriginAddresses []string `json:"origin_addresses"`
|
||||
// OriginAddresses contains the addresses returned by the API from your original request.
|
||||
//
|
||||
// These are formatted by the geocoder and localized according to the requested Language.
|
||||
OriginAddresses []string `json:"origin_addresses"`
|
||||
|
||||
// DestinationAddresses contains the addresses returned by the API from your original request.
|
||||
//
|
||||
// These are formatted by the geocoder and localized according to the requested Language.
|
||||
DestinationAddresses []string `json:"destination_addresses"`
|
||||
Rows []struct {
|
||||
|
||||
// Rows describes rows in the matrix.
|
||||
Rows []struct {
|
||||
// Elements describes columns in the matrix.
|
||||
Elements []struct {
|
||||
Status string `json:"status"`
|
||||
// Status indicates the status of the request, and will be one of StatusOK, StatusNotFound or StatusZeroResults.
|
||||
Status string `json:"status"`
|
||||
|
||||
// Duration indicates the total duration of this journey.
|
||||
Duration Duration `json:"duration"`
|
||||
|
||||
// Distance indicates the total distance of this journey.
|
||||
Distance Distance `json:"distance"`
|
||||
} `json:"elements"`
|
||||
} `json:"rows"`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue