Giter VIP home page Giter VIP logo

nova-maps-address's Introduction

Nova Maps Address

Nova Maps Address is a Nova field that allows the user to select an adress using the Google Places API and store it in a JSON column.

Table of Contents

  1. Installation
  2. Usage

Installation

To install the field simply run:

composer require mauricewijnia/nova-maps-address

You will need a Google Maps API key with access to the Maps, Places and Geocoding API. You can place the key in your .env file like this:

NOVA_MAPS_ADDRESS_KEY="your_key_here"

Usage

This fields stores its data as JSON in your column, so we will have to cast our column to an array.

To add the field to your resource you can do:

use Mauricewijnia\NovaMapsAddress\MapsAddress;
...
public function fields(Request $request) {
    return [
        ...
        MapsAddress::make(__('Address'), 'address'),
        ...
    ];
}

And in our model:

protected $casts = [
    'address' => 'array'
]

The resulting data will have this format:

{
    street_name: string,
    street_number: string,
    postal_code: string,
    city: string,
    country: string,
    formatted_address: string,
    latitude: float,
    longitude: float
    address_components: array // https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingAddressTypes
}

Options

You can change some of the settings for the map by call the respective option method:

MapsAddress::make(__('Address'), 'address')
    ->zoom(5)
    ->center(['lat' => 55.5, 'lng' => 5.5])
    ->types(['address' ,'establishment']);

You can also pass parameters to Map js request and all options available for map/autocomplete/geocoder class. For example to specify a language and regions and filter the components:

MapsAddress::make(__('shop_admin.places.address'), 'address')->types([])
                    ->scriptUrlParams(['region' => 'jp', 'language' => 'ja'])
                    ->autoCompleteOptions(['componentRestrictions' => ['country' => ['jp']]])
                    ->mapOptions(['componentRestrictions' => ['country' => ['jp']]])
Option Description Default
zoom Set the default zoom level of the map 10
center Set the initial centering point of the map ['lat' => 52.370216, 'lng' => 4.895168]
types Set the type of places that should be shown options are: establishment, address, geocode ['address']
allowMapClick Allow user to click on the map to get the address true
autoCompleteOptions Set options for AutoComplete class initialization. https://developers.google.com/maps/documentation/javascript/reference/places-widget#Autocomplete N/A
geocodeOptions Set options for Geocoder class initialization. https://developers.google.com/maps/documentation/javascript/reference/geocoder#GeocoderRequest N/A
mapOptions Set options for Map class initialization. https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions N/A
scriptUrlParams Set parameters during the request of Google Map API js. https://developers.google.com/maps/documentation/javascript/url-params N/A

nova-maps-address's People

Contributors

mauricewijnia 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.