1.1.9 • Published 5 years ago
mf-google-geocoder v1.1.9
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
4 years ago
1.2.5
4 years ago
1.2.4
4 years ago
1.2.3
4 years ago
1.2.2
4 years ago
1.2.1
4 years ago
1.2.0
5 years ago
1.1.9
5 years ago
1.1.8
5 years ago
1.1.7
5 years ago
1.1.6
5 years ago
1.1.5
5 years ago
1.1.4
5 years ago
1.1.3
5 years ago
1.1.2
5 years ago
1.1.1
5 years ago
1.1.0
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.7
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago