abode

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2022 License: MIT Imports: 6 Imported by: 0

README

abode 🏠

GoDoc Build Status Go Report Card license

  • Geocode one-line addresses.
  • Determine timezone information for a given address.
  • This package uses the Google Maps Web Services to geocode the address.
  • You will require the Geocoding API enabled, and optionally the [Timezone API] if you wish to also use Timezone().
  • Remember to set your GOOGLE_MAPS_API_KEY environment variable.

Installation

go get -u github.com/mattevans/abode

Example

Geocode an address:
addr := "193 Rogers Ave, Brooklyn, New York"

address, err := abode.ExplodeWithContext(ctx, addr)
if err != nil {
  return err
}

Returns...

abode.Address{
    AddressLine1:     "193 Rogers Avenue",
    AddressLine2:     "Brooklyn"
    AddressCity:      nil,
    AddressState:     "New York"
    AddressCountry:   "United States"
    AddressZip:       "11216"
    AddressLat:       40.6706073,
    AddressLng:       -73.9530182,
    FormattedAddress: "193 Rogers Ave, Brooklyn, NY 11216, USA",
}
Timezone information for an address:
addr := "193 Rogers Ave, Brooklyn, New York"

address, err := abode.Timezone(ctx, addr)
if err != nil {
  return err
}

Returns...

abode.Location{
    DstOffset:     0,
    RawOffset:     -17762,
    TimeZoneId:    "GMT-04:56:02",
    TimeZoneName:  "America/New_York"
}

Disclaimer

Ensure your end results are used in conjunction with a Google Map to avoid violating the Google Maps API Terms of Service.

Documentation

Index

Constants

View Source
const (
	AddressComponentTypeSubPremise      = "subpremise"
	AddressComponentTypePremise         = "premise"
	AddressComponentTypeStreetNumber    = "street_number"
	AddressComponentTypeRoute           = "route"
	AddressComponentTypeStreetAddress   = "street_address"
	AddressComponentTypeSubLocality     = "sublocality"
	AddressComponentTypeLocality        = "locality"
	AddressComponentTypeAdminAreaLevel1 = "administrative_area_level_1"
	AddressComponentTypeAdminAreaLevel2 = "administrative_area_level_2"
	AddressComponentTypeAdminAreaLevel3 = "administrative_area_level_3"
	AddressComponentTypeAdminAreaLevel4 = "administrative_area_level_4"
	AddressComponentTypeAdminAreaLevel5 = "administrative_area_level_5"
	AddressComponentTypeCountry         = "country"
	AddressComponentTypePostalCode      = "postal_code"
)

Define the different address component types.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	AddressLine1       *string  `json:"address_line1"`
	AddressLine2       *string  `json:"address_line2"`
	AddressCity        *string  `json:"address_city"`
	AddressState       *string  `json:"address_state"`
	AddressCountry     *string  `json:"address_country"`
	AddressCountryCode *string  `json:"address_country_code"`
	AddressZip         *string  `json:"address_zip"`
	AddressLat         *float64 `json:"address_lat"`
	AddressLng         *float64 `json:"address_lng"`
	FormattedAddress   *string  `json:"formatted_address"`
}

Address represents a response Address from abode.

func Explode

func Explode(address string) (*Address, error)

Explode takes a one-line address string, explodes it using gmaps.Geocode() and returns an *Address. Deprecated: Use ExplodeWithContext instead.

func ExplodeWithContext added in v0.3.0

func ExplodeWithContext(ctx context.Context, address string) (*Address, error)

ExplodeWithContext takes a one-line address string, explodes it using gmaps.Geocode() and returns an *Address.

type Location added in v0.3.0

type Location struct {
	DstOffset    int    `json:"dst_offset"`
	RawOffset    int    `json:"raw_offset"`
	TimeZoneId   string `json:"time_zone_id"`
	TimeZoneName string `json:"time_zone_name"`
}

func Timezone added in v0.3.0

func Timezone(ctx context.Context, address string) (*Location, error)

Timezone takes a one-line address string, and determine timezone/location data for it using gmaps.Timezone().

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL