A versatile TypeScript library for geocoding and address search using multiple providers.
npm install dangnh-search-libA versatile TypeScript library for geocoding and address search using multiple providers.
- Support for multiple geocoding providers:
- Google Maps
- Photon
- Nominatim (OpenStreetMap)
- LocationIQ
- Flexible API for easy integration
- TypeScript support
Install the package using npm
bash
npm install address-search-lib
typescript
import { AddressSearch } from 'address-search-lib';
const addressSearch = new AddressSearch();
// Search using the default provider (Nominatim)
addressSearch.search('1600 Amphitheatre Parkway, Mountain View, CA')
.then(results => console.log(results))
.catch(error => console.error(error));
typescript
// Use Google Maps geocoder
addressSearch.search('1600 Amphitheatre Parkway, Mountain View, CA', 'gg')
.then(results => console.log(results))
.catch(error => console.error(error));
// Use Photon geocoder
addressSearch.search('1600 Amphitheatre Parkway, Mountain View, CA', 'pton')
.then(results => console.log(results))
.catch(error => console.error(error));
// Use LocationIQ geocoder
addressSearch.search('1600 Amphitheatre Parkway, Mountain View, CA', 'iq')
.then(results => console.log(results))
You can also use the geocoders individually:
typescript
import { GoogleGeocoder, NominatimGeocoder, PhotonGeocoder, LocationIQGeocoder } from 'address-search-lib';
const googleGeocoder = new GoogleGeocoder();
const nominatimGeocoder = new NominatimGeocoder();
const photonGeocoder = new PhotonGeocoder();
const locationIQGeocoder = new LocationIQGeocoder('your-api-key');
// Use Google Maps geocoder
googleGeocoder.geocode('1600 Amphitheatre Parkway, Mountain View, CA')
.then(results => console.log(results))
.catch(error => console.error(error));
You can pass options when initializing the AddressSearch class:
typescript
const options = {
googleOptions: {
headless: false,
timeout: 60000
},
locationIQKey: 'your-locationiq-api-key'
};
const addressSearch = new AddressSearch(options);
- options: Optional configuration object
- googleOptions: Options for Google Maps geocoder
- locationIQKey: API key for LocationIQ
- place: The address or place to search for
- type: The geocoder to use (default: 'nomi')
- 'gg': Google Maps
- 'pton': Photon
- 'iq': LocationIQ
- 'nomi': Nominatim
The GeocodingResult interface represents the structure of the geocoding results
- axios
- puppeteer-extra
- puppeteer-extra-plugin-stealth
This project is licensed under the MIT License.