A latitude & longitude selector

Related tags

Geolocation latlong
Overview

经纬度选择器/Latitude and longitude selector

这个扩展用来帮助你在form表单中选择经纬度,用来替代Laravel-admin中内置的Form\Field\Map组件, 组件支持的地图包括Google map百度地图高德地图腾讯地图Yandex map.

This extension is used to help you select the latitude and longitude in the form, which is used to replace the Laravel-admin built in Form\Field\Map component. The supported maps include Google map, Baidu map, AMap, Tencent Map, Yandex map.

Installation

// For laravel-admin 1.x
composer require laravel-admin-ext/latlong:1.x -vvv

// For laravel-admin 2.x
composer require laravel-admin-ext/latlong:2.x -vvv

Configuration

Open config/admin.php and add the following configuration to the extensions section:

    'extensions' => [

        'latlong' => [

            // Whether to enable this extension, defaults to true
            'enable' => true,

            // Specify the default provider
            'default' => 'google',

            // According to the selected provider above, fill in the corresponding api_key
            'providers' => [

                'google' => [
                    'api_key' => '',
                ],
                
                'yandex' => [
                    'api_key' => '',
                ],

                'baidu' => [
                    'api_key' => 'xck5u2lga9n1bZkiaXIHtMufWXQnVhdx',
                ],

                'tencent' => [
                    'api_key' => 'VVYBZ-HRJCX-NOJ4Z-ZO3PU-ZZA2J-QPBBT',
                ],

                'amap' => [
                    'api_key' => '3693fe745aea0df8852739dac08a22fb',
                ],
            ]
        ]
    ]

Usage

Suppose you have two fields latitude and longitude in your table that represent latitude and longitude, then use the following in the form:

$form->latlong('latitude', 'longitude', 'Position');

// Set the map height
$form->latlong('latitude', 'longitude', 'Position')->height(500);

// Set the map zoom
$form->latlong('latitude', 'longitude', 'Position')->zoom(16);

// Set default position
$form->latlong('latitude', 'longitude', 'Position')->default(['lat' => 90, 'lng' => 90]);

Use in show page

$show->field('Position')->latlong('lat_column', 'long_column', $height = 400, $zoom = 16);

Donate

如果觉得这个项目帮你节约了时间,不妨支持一下;)

-1

License

Licensed under The MIT License (MIT).

Comments
  • Map not working

    Map not working

    Site on local. PHP: 7.3 Laravel: v7.2.2 Laravel-admin: v1.8.2

    Method Encore\Admin\Latlong\Latlong::zoom does not exist.

    $form->latlong('content->lat', 'content->lon', 'Position')->zoom(5);
    

    If use:

    $form->latlong('content->lat', 'content->lon', 'Местоположение')->default(['zoom' => 5]);
    

    Then:

    Снимок экрана от 2020-09-02 21-07-58

    In config/admin.php:

    'extensions' => [
            'latlong' => [
                'enable' => true,
                'default' => 'yandex',
                'providers' => [
                    'google' => [
                        'api_key' => env('GOOGLE_MAP_API_KEY'),
                    ],
                    'yandex' => [
                        'api_key' => env('YANDEX_MAP_API_KEY'),
                    ],
                ]
            ],
        ],
    
    opened by sd-evo 3
  • Fix feature getCurrentPosition

    Fix feature getCurrentPosition

    When setAutoPosition is defined, the blade file need to take value from variable $value['lat'] and $value['lng'], but the function of set current position loaded after the blade, and the blade get null value from that variable. So this is how to avoid that problem and some fixes for google maps api too

    opened by vonsogt 2
  • In production or on CPanel latlong extension does not work.

    In production or on CPanel latlong extension does not work.

    its only working while project is running using php artisan serve. admin/config.php contains Screenshot 2021-04-28 at 8 49 16 PM

    it always returns Field type [latlong] does not exist. while project is hosted on cpanel. Screenshot 2021-04-28 at 8 46 01 PM

    opened by mohsinayoob 2
  • ViewException In latlong.blade.php line 17

    ViewException In latlong.blade.php line 17

     ViewException In latlong.blade.php line 17 :
      Undefined variable: provider (View: /app/vendor/laravel-admin-ext/latlong/resources/views/latlong.blade.php)
    

    版本信息:

    laravel-admin: 1.8.*
    laravel-admin-extensions: 1.2
    

    修改Latlong.php文件中reader方法可解决此问题:

    public function render()
        {
            $this->script = Extension::getProvider()
                ->setParams([
                    'zoom' => $this->zoom
                ])
                ->setAutoPosition($this->autoPosition)
                ->applyScript($this->id);
    
            $variables = [
                'height'   => $this->height,
                'provider' => Extension::config('default'),
            ];
            $this->addVariables($variables);
    
            return parent::fieldRender($variables);
        }
    
    opened by tingfeng-key 1
  • Disable getCurrentPosition

    Disable getCurrentPosition

    There is no point of navigator.geolocation.getCurrentPosition by default. How I can disable this behaviour? https://github.com/laravel-admin-extensions/latlong/blob/master/src/Map/Google.php#L37

    opened by vlados 1
  •    Class 'Encore\Admin\Assets' not found

    Class 'Encore\Admin\Assets' not found

    Executing command (CWD): '/usr/bin/php7.3' -d allow_url_fopen='1' -d disable_functions='' -d memory_limit='-1' artisan package:discover --ansi

    Error

    Class 'Encore\Admin\Assets' not found

    opened by weishuiliang 0
  • yandex instead yadex

    yandex instead yadex

    you have mistype in config/admin.php It should be yandex instead yadex Otherwise we got error {"exception":"[object] (ErrorException(code: 0): Undefined index: yadex at C:\laragon\www\laravel\vendor\laravel-admin-ext\latlong\src\Extension.php:43)

                    'yandex' => [
                        'api_key' => '',
                    ],
    
    opened by schel4ok 0
  • ViewException In latlong.blade.php line 11

    ViewException In latlong.blade.php line 11

    Hello, here's my case:

    Laravel-admin: v1.8.19 laravel-admin-ext/latlong: v1.2.4

    My code:

    admin.php

    'latlong' => [
    
                // Whether to enable this extension, defaults to true
                'enable' => true,
    
                // Specify the default provider
                'default' => 'google',
    
                // According to the selected provider above, fill in the corresponding api_key
                'providers' => [
    
                    'google' => [
                        'api_key' => '***********8siSug',
                    ]
         ]
    ]
    

    OfficeController.php: $form->latlong('lat', 'long', 'Office Location');

    I get the following error:

     ViewException In latlong.blade.php line 11 :
      Trying to access array offset on value of type null (View: /var/www/html/estiqdam/vendor/laravel-admin-ext/latlong/resources/views/latlong.blade.php)
    

    Stack trace:

    #0 /var/www/html/estiqdam/vendor/laravel-admin-ext/latlong/src/../resources/views/latlong.blade.php(11): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() #1 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(107): require('/var/www/html/e...') #2 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(108): Illuminate\Filesystem\Filesystem::Illuminate\Filesystem{closure}() #3 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(58): Illuminate\Filesystem\Filesystem->getRequire() #4 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(61): Illuminate\View\Engines\PhpEngine->evaluatePath() #5 /var/www/html/estiqdam/vendor/facade/ignition/src/Views/Engines/CompilerEngine.php(37): Illuminate\View\Engines\CompilerEngine->get() #6 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/View/View.php(139): Facade\Ignition\Views\Engines\CompilerEngine->get() #7 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/View/View.php(122): Illuminate\View\View->getContents() #8 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/View/View.php(91): Illuminate\View\View->renderContents() #9 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/Traits/HasAssets.php(338): Illuminate\View\View->render() #10 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/Form/Field.php(1553): Encore\Admin\Admin::component() #11 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/Form/Field.php(1565): Encore\Admin\Form\Field->render() #12 /var/www/html/estiqdam/vendor/laravel-admin-ext/latlong/src/Latlong.php(125): Encore\Admin\Form\Field->fieldRender() #13 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/../resources/views/form.blade.php(31): Encore\Admin\Latlong\Latlong->render() #14 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(107): require('/var/www/html/e...') #15 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(108): Illuminate\Filesystem\Filesystem::Illuminate\Filesystem{closure}() #16 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(58): Illuminate\Filesystem\Filesystem->getRequire() #17 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(61): Illuminate\View\Engines\PhpEngine->evaluatePath() #18 /var/www/html/estiqdam/vendor/facade/ignition/src/Views/Engines/CompilerEngine.php(37): Illuminate\View\Engines\CompilerEngine->get() #19 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/View/View.php(139): Facade\Ignition\Views\Engines\CompilerEngine->get() #20 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/View/View.php(122): Illuminate\View\View->getContents() #21 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/View/View.php(91): Illuminate\View\View->renderContents() #22 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/Form/Builder.php(688): Illuminate\View\View->render() #23 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/Form.php(1461): Encore\Admin\Form\Builder->render() #24 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/Layout/Column.php(100): Encore\Admin\Form->render() #25 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/Layout/Row.php(80): Encore\Admin\Layout\Column->build() #26 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/Layout/Content.php(215): Encore\Admin\Layout\Row->build() #27 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/Layout/Content.php(308): Encore\Admin\Layout\Content->build() #28 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Http/Response.php(69): Encore\Admin\Layout\Content->render() #29 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Http/Response.php(35): Illuminate\Http\Response->setContent() #30 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Routing/Router.php(820): Illuminate\Http\Response->__construct() #31 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Routing/Router.php(789): Illuminate\Routing\Router::toResponse() #32 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Routing/Router.php(721): Illuminate\Routing\Router->prepareResponse() #33 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Routing\Router->Illuminate\Routing{closure}() #34 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/Middleware/Permission.php(46): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #35 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Encore\Admin\Middleware\Permission->handle() #36 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/Middleware/Bootstrap.php(15): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #37 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Encore\Admin\Middleware\Bootstrap->handle() #38 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/Middleware/LogOperation.php(38): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #39 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Encore\Admin\Middleware\LogOperation->handle() #40 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/Middleware/Pjax.php(24): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #41 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Encore\Admin\Middleware\Pjax->handle() #42 /var/www/html/estiqdam/vendor/encore/laravel-admin/src/Middleware/Authenticate.php(28): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #43 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Encore\Admin\Middleware\Authenticate->handle() #44 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #45 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Routing\Middleware\SubstituteBindings->handle() #46 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #47 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle() #48 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #49 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\View\Middleware\ShareErrorsFromSession->handle() #50 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #51 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest() #52 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Session\Middleware\StartSession->handle() #53 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #54 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle() #55 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #56 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Cookie\Middleware\EncryptCookies->handle() #57 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #58 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Routing/Router.php(723): Illuminate\Pipeline\Pipeline->then() #59 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Routing/Router.php(698): Illuminate\Routing\Router->runRouteWithinStack() #60 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Routing/Router.php(662): Illuminate\Routing\Router->runRoute() #61 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Routing/Router.php(651): Illuminate\Routing\Router->dispatchToRoute() #62 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(167): Illuminate\Routing\Router->dispatch() #63 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http{closure}() #64 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #65 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle() #66 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle() #67 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #68 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle() #69 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TrimStrings->handle() #70 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #71 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle() #72 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #73 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle() #74 /var/www/html/estiqdam/vendor/fruitcake/laravel-cors/src/HandleCors.php(38): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #75 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fruitcake\Cors\HandleCors->handle() #76 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #77 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Http\Middleware\TrustProxies->handle() #78 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() #79 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(142): Illuminate\Pipeline\Pipeline->then() #80 /var/www/html/estiqdam/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(111): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter() #81 /var/www/html/estiqdam/index.php(55): Illuminate\Foundation\Http\Kernel->handle() #82 {main}

    opened by amismailz 0
  • 显示时值传入失败

    显示时值传入失败

    Laravel 8.51.0 laravel-admin:1.8.13 latlong:1.2.4

    当使用以下命令时,所传递的值不会被正常显示,而是直接将定位跳转到当前电脑定位 $show->field('Position')->latlong('dizhi.lat_column', 'dizhi.long_column', $height = 400, $zoom = 16);

    opened by acecx 0
  • Undefined variable: provider

    Undefined variable: provider

    "laravel-admin-ext/latlong": "1.2", "laravel-admin": "1.8.11", "laravel": "^5.7",

    已经跑 php artisan view:clear 了。还是有这个问题

    ErrorException In 18d91ce0cba1ef8f7ac4eda2b84c2bde221bda8b.php line 17 : Undefined variable: provider (View: C:\xampp\htdocs\vending\vendor\laravel-admin-ext\latlong\resources\views\latlong.blade.php) (View: C:\xampp\htdocs\vending\vendor\laravel-admin-ext\latlong\resources\views\latlong.blade.php) (View: C:\xampp\htdocs\vending\vendor\laravel-admin-ext\latlong\resources\views\latlong.blade.php)

    opened by JayChew 0
  • 模板-传值错误

    模板-传值错误

    环境: "require": { "php": "^7.1.3", "encore/laravel-admin": "^1.8", "fideloper/proxy": "^4.0", "laravel-admin-ext/latlong": "^1.2", "laravel/framework": "5.8.*", "laravel/tinker": "^1.0", "overtrue/laravel-lang": "~3.0", "symfony/translation": "4.3.8" }, 包代码: /** * {@inheritdoc} * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string */ public function render() { $this->script = Extension::getProvider()->applyScript($this->id);

        $variables = [
            'height'   => $this->height,
            'provider' => Extension::config('default'),
        ];
    
        return parent::render()->with($variables);
    }
    

    可用代码: /** * {@inheritdoc} * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string */ public function render() { $this->script = Extension::getProvider()->applyScript($this->id);

        $variables = [
            'height'   => $this->height,
            'provider' => Extension::config('default'),
        ];
    
        $this->addVariables($variables);
    
        return parent::render();
    }
    

    是我的laravel 或者 laravel-admin 版本问题吗?

    opened by zhubing361 0
Owner
Extensions for laravel-admin
Extensions for laravel-admin
Extensions for laravel-admin
Simple address and contact management for Laravel with automatically geocoding to add longitude and latitude

Laravel Addresses Simple address and contact management for Laravel with automatically geocoding to add longitude and latitude. Installation Require t

Chantouch Sek 2 Apr 4, 2022
Magento 2 custom extension to add custom attributes(longitude, latitude) to customer address

Magento 2 custom extension to add custom attributes(longitude, latitude) to customer address. Then save them to quote model and copy them from quote address to order address on bakend, frontend, rest api

MageArab 2 Jul 14, 2022