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

aurelia-google-places

v1.0.6

Published

A Google Places Autocomplete plugin for Aurelia.

Downloads

11

Readme

aurelia-google-places

A Google Places Autocomplete plugin for Aurelia.

This plugin is a custom element build with the Google Places AutocompleteService instead of the Google Places Autocomplete class. You can use this plugin easily in a form and don't have to deal with the asynchronous placed_changed event. Simply bind a value to the element to get the value of the input in your form. The downside is that you still need to do your own geocoding if you want to have geographic coordinates of the address. Luckily, this can be easily done with the Google Geocoder.

Installation

Webpack/Aurelia CLI

npm install aurelia-google-places --save

JSPM

jspm install aurelia-google-places

Bower

bower install aurelia-google-places

Configuration

Add to package.json

  "aurelia": {
    "build": {
      "resources": [
        "aurelia-google-places"
      ]
    }
  }

Inside of your main.js or main.ts file simply load the plugin inside of the configure method using .plugin().

export async function configure(aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging();

  aurelia.use
    .plugin('aurelia-google-places', config => {
      config.options({
        apiScriptLoadedEvent: 'aurelia-plugins:google-maps:api-script-loaded', // if loadApiScript is false, the event that is subscribed to to know when the Google Maps API is loaded by another plugin
        key: '', // your Google API key retrieved from the Google Developer Console
        language: 'es', // see https://developers.google.com/maps/documentation/javascript/localization
        libraries: 'places', // see https://developers.google.com/maps/documentation/javascript/libraries
        loadApiScript: true|false, // whether or not the <script> tag of the Google Maps API should be loaded
        options: { types: ['geocode'] } // see https://developers.google.com/maps/documentation/javascript/places-autocomplete#add_autocomplete
      });
    });

    await aurelia.start();
    aurelia.setRoot('app');
}

Usage

Once Google Places Autocomplete is configured, to use it simply add the custom element <aup-google-places></aup-google-places> in your view.

Google Maps API loaded

The aurelia-plugins:google-places-autocomplete:api-script-loaded event is published when the Google Maps API Script is completely loaded. A Promise is returned as payload. This event is used together with other Aurelia Plugins in combination with the option loadApiScript=false to make sure the Google Maps API Script is loaded only once.

Google Places Autocomplete needs at least the library places. Perhaps the other Aurelia Plugin that loads the Google Maps API Script doesn't include the library places by default. If so, add it to the libraries option of the other Aurelia Plugin.

Get the input value

Bind the value attribute to <aup-google-places></aup-google-places> to get the value selected from the Google Places AutocompleteService. Do your own geocoding if necessary. You can also easily validate the value with aurelia-validation.

<form submit.delegate="onSubmit()">
  <aup-google-places value.bind="value"></aup-google-places>
  <button type="submit">Submit</button>
</form>
export class App {
  value = '';
  
  async onSubmit() {
    var place = await this.geocode(this.value);
    console.log(place);
  }
  
  geocode(value) {
    return new Promise((resolve, reject) => {
      new google.maps.Geocoder().geocode({ address: value }, (results, status) => {
        status === google.maps.GeocoderStatus.OK ? resolve(results[0]) : reject();
      });
    });
  }
}

Other attributes

The other attributes that can be used on <aup-google-places></aup-google-places> are:

  • placeholder: The placeholder shown on the input.
  • selectClass: The CSS class added to the selected item in the autocomplete when using up and down keys.