1.2.6 • Published 2 years ago
mf-google-geocoder v1.2.6
mf-google-geocoder
JS library that uses Google Geocoding API (https only) and parses the response into a flat, readable and minimal object.
Usage Example
const address = '672 Franklin Ave #1fl, Brooklyn, NY 11238, USA';
try {
const result = await fromAddressText(address, { apiKey, mfAutoFix: true });
console.log(result.city)
console.log(result.location)
console.log(result.zip)
} catch (e) {
if (e.name === 'MissingAddressDetailsError') { // or check if instanceof
console.log(e.missingTypes);
}
}
Functions and Interfaces
From address text
Gets text and returns AddressDetails
interface and returns AddressDetails
interface
via
function fromAddressText(addressText: string, options: Options)
From Google Geocoder response
Gets GoogleGeoCodeResponse
and returns AddressDetails
interface
via
function fromGoogleGeoCode(googleGeoCodeResponse: GoogleGeoCodeResponse, options: Options)
Returned Value
interface AddressDetails {
/** geometry.location */
location: Geo;
/** address component with 'country' and 'political' types */
country: string;
/** address component with 'administrative_area_level_1' and 'political' types */
state: string;
/** address component with 'administrative_area_level_2' and 'political' types */
county: string;
/** address component with 'neighborhood \ sublocality \ locality' and 'political' types */
city: string;
/** address component with 'route' type */
street: string;
/** address component with 'street_number' type */
streetNumber: string | null;
/** address component with 'postal_code' type */
zip: string;
/** address component with 'postal_code_suffix' type */
zipSuffix: string | null;
/** formatted_address */
fullAddress: string;
/** address component with 'subpremise' type */
address2: string | null;
/** original google API response */
googleGeoCodeResponse: GoogleGeoCodeResponse;
}
MissingAddressDetailsError
:
Throws MissingAddressDetailsError
with missingTypes: (AddressType | GeocodingAddressComponentType)[]
if one of the required fields are missing.
options
interface Options {
/** google API key */
apiKey: string,
/** indicates if to change the original address if fields are missing. Default is true */
mfAutoFix?: boolean;
}
1.2.6
2 years ago
1.2.5
2 years ago
1.2.4
2 years ago
1.2.3
2 years ago
1.2.2
2 years ago
1.2.1
3 years ago
1.2.0
3 years ago
1.1.9
3 years ago
1.1.8
3 years ago
1.1.7
3 years ago
1.1.6
3 years ago
1.1.5
3 years ago
1.1.4
3 years ago
1.1.3
3 years ago
1.1.2
3 years ago
1.1.1
3 years ago
1.1.0
3 years ago
1.0.9
3 years ago
1.0.8
3 years ago
1.0.7
3 years ago
1.0.6
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago