Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added building and entrances support in geocoding requests #306

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions geocoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ var geocodingAPI = &apiConfig{
// Geocode makes a Geocoding API request
func (c *Client) Geocode(ctx context.Context, r *GeocodingRequest) (GeocodingResponse, error) {
if r.Address == "" && len(r.Components) == 0 && r.LatLng == nil {
return GeocodingResponse{}, errors.New("maps: address, components and LatLng are all missing")
return GeocodingResponse{}, errors.New(
"maps: address, components and LatLng are all missing",
)
}

var response struct {
Expand All @@ -54,14 +56,17 @@ func (c *Client) Geocode(ctx context.Context, r *GeocodingRequest) (GeocodingRes
}

// ReverseGeocode makes a Reverse Geocoding API request
func (c *Client) ReverseGeocode(ctx context.Context, r *GeocodingRequest) (GeocodingResponse, error) {
func (c *Client) ReverseGeocode(
ctx context.Context,
r *GeocodingRequest,
) (GeocodingResponse, error) {
// Since Geocode() does not allow a nil LatLng, whereas it is allowed here
if r.LatLng == nil && r.PlaceID == "" {
return GeocodingResponse{}, errors.New("maps: LatLng and PlaceID are both missing")
}

var response struct {
Results []GeocodingResult `json:"results"`
Results []GeocodingResult `json:"results"`
AddressDescriptor AddressDescriptor `json:"address_descriptor"`
commonResponse
}
Expand Down Expand Up @@ -229,6 +234,20 @@ type GeocodingResult struct {
// However, if the result is in a remote location (for example, an ocean or desert)
// only the global code may be returned.
PlusCode AddressPlusCode `json:"plus_code"`

// Entrances define list of entry or exit points into a place
// (see https://developers.google.com/maps/documentation/geocoding/building-attributes).
// This can be requested by sending extra_computations by the
// GeocodingRequest.Custom parameter
// (see https://developers.google.com/maps/documentation/geocoding/requests-geocoding).
Entrances []Entrance `json:"entrances"`

// Buildings contain 2D polygon representing the surface area covered by
// the building (see https://developers.google.com/maps/documentation/geocoding/building-attributes).
// This can be requested by sending extra_computations by the
// GeocodingRequest.Custom parameter
// (see https://developers.google.com/maps/documentation/geocoding/requests-geocoding).
Buildings []Building `json:"buildings"`
}

// AddressPlusCode (see https://en.wikipedia.org/wiki/Open_Location_Code and https://plus.codes/)
Expand Down Expand Up @@ -264,3 +283,26 @@ type AddressGeometry struct {
Viewport LatLngBounds `json:"viewport"`
Types []string `json:"types"`
}

// DisplayPolygon is the bounding polygon of a building
type DisplayPolygon struct {
Coordinates [][][]float64 `json:"coordinates"`
Type string `json:"type"`
}

// BuildingOutline is the outline of a building
type BuildingOutline struct {
DisplayPolygon DisplayPolygon `json:"display_polygon"`
}

// Building is the boundary of a building
type Building struct {
BuildingOutlines []BuildingOutline `json:"building_outlines"`
PlaceId string `json:"place_id"`
}

// Entrance is the entrance of a structure or building
type Entrance struct {
Location LatLng `json:"location"`
BuildingPlaceId string `json:"building_place_id"`
}
Loading