npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@venditan/address-lookup

v1.1.0

Published

Venditan Google Places API solution for handling address/postcode lookup

Downloads

23

Readme

npm version

Venditan Address Lookup

Google Places API solution for handling address/postcode lookup

Features

This package has the following features:

  • Lookup addresses using Google Places API
  • Complete partial postcodes using the postcodes.io API
  • Logging lookup with VC for billing

How does it work?

Venditan Address Lookup jQuery plugin was written so it will do a lot of the heavy lifting for you.

$('#autocomplete').addressLookup();

Note: it is important to ensure the element it is called against is an input element or Google Places API will throw an error in your console.

The snippet above is enough to get the address lookup working, but you will want to view jquery.address-lookup.js as it provides optional settings that we do override:

$('#autocomplete').addressLookup({
    callback: function() {},
    excludeTerms: [],
    fields: [],
    logLookup: true,
    logURL: '/log_address_lookup',
    postLog: function() {},
    logData: {},
    logPostVariable: 'postcode',
    restrictions: {},
    types: []
});

The full list of hooks are:

  • callback - allows you to call a function to populate the place detail returned
  • postLog - if you wish to do something once we have logged the lookup with VC

The following settings are also available:

  • excludeTerms - array of address line contents to cleanse from the address
  • fields - sets the fields for the API to return with the Places Detail request API Reference and Fields
  • logLookup - set whether to log the lookup with VC or not
  • logURL - set the URL to post to so that VC can log the lookup request
  • logPostVariable - set the parameter name to use in the post request when logging the usage
  • logData - set additional parameters, that you would like to pass to logURL
  • restrictions - sets the restrictions for the API results, for example, limit to a country API Reference and Restrictions
  • types - sets the type of data to return, by default it will return residential and businesses API Reference and Types

How to get and use the Place Detail object

Within your callback function you will want to access the Place Detail object so you can populate your form with the address information.

To do this you need to simply do the following:

var obj_place = $('#autocomplete').addressLookup('get', 'place');

This will allow you to access the fields you requested in the following manner:

  • obj_place.address_components - the address line object
    • This is the full address, broken down into an array of lines
  • obj_place.types - the type(s) of the address returned based on the request performed, such as establishment, street_address, postal_code, etc.
    • You can use this to determine the type of address returned - such as choosing to show the Business name if it is an establishment or adding a house number/name field if it was a postal_code request.
  • obj_place.name - the name of the address returned
    • Recommended that this is only used if the type of address returned is an establishment.