1.0.8 • Published 5 years ago

@guillaumedeslandes/vue2-geocoder v1.0.8

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Vue Geocoder

A vue.js plugin to interact with google maps api.

How to initialize Vue Geocoder

A vue 2 plugin to interact with google maps api that will query the google maps API to retrieve location results.

import Geocoder from "@pderas/vue2-geocoder";

Vue.use(Geocoder, {
    googleMapsApiKey: GOOGLE_MAPS_API_KEY
});

Usage

General usage: js.$geocoder.[FUNCTION_NAME]

Address Example
Vue.$geocoder.setDefaultMode('address');      // this is default
var addressObj = {
    address_line_1: '1600 Amphitheatre Parkway',
    address_line_2: '',
    city:           'Mountain View',
    state:          'CA',               // province also valid
    zip_code:       '94043',            // postal_code also valid
    country:        'United States'
}
Vue.$geocoder.send(addressObj, response => { console.log(response) });

Its important to note that even if your country is set in the address object to the specified country, it is still possible to pull results from other countries. If you want to limit the results to a specific country, you must set the country code in the geocoder.

Vue.$geocoder.setDefaultCountryCode('CA');

Click here for Country Codes

Lat Lng Example
Vue.$geocoder.setDefaultMode('lat-lng');    // this is default
var latLngObj = {
    lat: 37.421512,
    lng: -122.084101,
    result_type: 'administrative_area_level_1' // optional
}
Vue.$geocoder.send(latLngObj, response => { console.log(response) });
Place ID Example
Vue.$geocoder.setDefaultMode('place_id');    // this is default
var placeObj = {
    place_id: 'ChIJD7fiBh9u5kcRYJSMaMOCCwQ'
}
Vue.$geocoder.send(placeObj, response => { console.log(response) });
Extra parameters
Vue.$geocoder.setDefaultMode('place_id');    // this is default
var placeObj = {
    place_id: 'ChIJD7fiBh9u5kcRYJSMaMOCCwQ',
    language: 'en'
}
Vue.$geocoder.send(placeObj, response => { console.log(response) });

Click here for Language Codes

License

This project is covered under the MIT License. Feel free to use it wherever you like.