GithubHelp home page GithubHelp logo

idragon81 / nova-google-autocomplete-field Goto Github PK

View Code? Open in Web Editor NEW

This project forked from emilianotisato/nova-google-autocomplete-field

0.0 0.0 0.0 133 KB

Address Autocomplete with Google Place API (full metadata available)

PHP 43.71% Vue 48.48% JavaScript 7.65% CSS 0.15%

nova-google-autocomplete-field's Introduction

Nova Google AutoComplete Field Package

This field allows you to work with Google Places API to autocomplete on user input and get the full real address with all the metadata (like latitude and longitude).

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require emilianotisato/nova-google-autocomplete-field

Now publish config and localization files:

php artisan vendor:publish --provider="EmilianoTisato\GoogleAutocomplete\FieldServiceProvider"

Create an app and enable Places API and create credentials to get your API key https://console.developers.google.com

Add the below to your .env file

ADDRESS_AUTOCOMPLETE_API_KEY=############################

Add the below to /resources/views/vendor/nova/layout.blade.php (this you can copy from the nova repository to override the original)

  • To get results in specific language add &language=en to the below script url
<script src="https://maps.googleapis.com/maps/api/js?key={{config('google-autocomplete.api_key')}}&libraries=places"></script>

Usage

Add the use declaration to your resource and use the fields:

use EmilianoTisato\GoogleAutocomplete\GoogleAutocomplete;
// ....

GoogleAutocomplete::make('Address'),

//You can add a country or countries to autocomplete or leave empty for all.

// Specify a single country
GoogleAutocomplete::make('Address')
          ->countries('US'),

// Specify multiple countries [array]
GoogleAutocomplete::make('Address')
          ->countries(['US','AU]),

You can access other parameter like latitude, longitude, street_number, route, locality, administrative_area_level_1, country, postal_code, along with everything available in the - every field present in the PlaceResult object

use EmilianoTisato\GoogleAutocomplete\AddressMetadata;
use EmilianoTisato\GoogleAutocomplete\GoogleAutocomplete;

// Now this address field will search and store the address as a string, but also made available the values in the withValues array
GoogleAutocomplete::make('Address')->withValues(['latitude', 'longitude']),

// And you can store the values by autocomplete like this
AddressMetadata::make('lat')->fromValue('latitude'),
AddressMetadata::make('long')->fromValue('longitude'),

// You can disable the field so the user can't edit the metadata
AddressMetadata::make('long')->fromValue('longitude')->disabled(),

// Or you can make the field invisible in the form but collect the data anyways
AddressMetadata::make('long')->fromValue('longitude')->invisible(),

You can change the type of places that are returned by the autocomplete using the placeType() method. You can use any of the values listed at https://developers.google.com/places/supported_types#table3

use EmilianoTisato\GoogleAutocomplete\AddressMetadata;
use EmilianoTisato\GoogleAutocomplete\GoogleAutocomplete;

// This autocomplete field will return results that match a business name instead of address.
// All the same address data is still stored.  
GoogleAutocomplete::make('Address')->placeType('establishment');

Localization

If you want this package in your language, just create a json lang file in your resources/lang/vendor/google-autocomplete folder. Example

resources/lang/vendor/google-autocomplete/es.json

nova-google-autocomplete-field's People

Contributors

bernhardh avatar emilianotisato avatar ibrahim-mubarak avatar nickpoulos avatar skullbock avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.