Algolia a javascript library for address search autocomplete
Posted By : Sachin Arora | 26-Sep-2018
Algolia is a javascript library which provides a fast, distributed and an easy way to use addresses search autocomplete on our website. Basically,
Getting Started
installing it using
npm install places.js --save
Using CDN :
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
After installing the library in our project we need to add an input tag on which we need to use our address search autocomplete.
<input type="search" id="address-input" placeholder="Where are we going?" />
After, adding an input tag we need to initialize the places.js library :
var places = require('places.js');
var placesAutocomplete = places({
container: document.querySelector('#address-input')
});
Usage
To make any of our input boxes into an address search bar you need to make sure that you have included initialized places.js library and use the following code :
var options = {
container: '#my-input-DOM-selector',
// ...
};
places(options);
Here is a small example using it :
<input type="search" id="address-input" placeholder="Where are we going?" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script>
var placesAutocomplete = places({
container: document.querySelector('#address-input')
});
</script>
Algolia places library also provides us with further more options that we can pass to our places(options) function like type it helps us to restrict our search results to specific
which are the city, country, address, townhall, and airport, by default it is searched in all types? It also provides a language option for that you just need to pass two letters language codes.
Example with options:
var placesAutocomplete = {
container: document.querySelector('#demo'),
language: 'de', // Receives results in German
countries: ['us', 'ru'], // Search in the United States of America and in the Russian Federation
type: 'city', // Search only for cities names
aroundLatLngViaIP: false // disable the extra search/boost around the source IP
};
So, this library is our solution for autocomplete address search with further more options and not only these options it also provides some predefined methods and events which can be used according to our requirements.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Sachin Arora
Sachin is ambitious and hardworking individual with broad skills,He have the capabilities to build captivating UI applications . One of his key strength is building a strong bond with the team in order to deliver the best results on time .