clevyr/laravel-geocoder 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

clevyr/laravel-geocoder

最新稳定版本:v0.1.1

Composer 安装命令:

composer require clevyr/laravel-geocoder

包简介

Handles geocoding an address into lat/lng with multiple providers

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Handles geocoding an address into lat/lng based on cloud providers.

Note: Currently only supports using Google as a Geocoding provider. As we prioritize it, we will implement MapBox as well.

Installation

You can install the package via composer:

composer require clevyr/laravel-geocoder

Next, publish the plugin assets:

php artisan vendor:publish --provider="Clevyr\LaravelGeocoder\LaravelGeocoderServiceProvider"

This is the contents of the published config file (without descriptive comments):

return [
    'adapter' => 'google',
    'test-adapter' => 'test',
    'test' => [
        'lat' => 35.4771302,
        'lng' => -97.5283204,
    ],
];

Set up Google Geocoding

First, you need to set up a Google Geocoding API Key

Then, you will need to set the following ENV variable in your Laravel application:

GOOGLE_CLOUD_API_KEY=

Usage

use Clevyr\LaravelGeocoder\LaravelGeocoder;

$coords = LaravelGeocoder::GetLatLngFromAddress(
    '123 Test Ln',
    null,
    'New York',
    'NY',
    '10001',
);

echo $coords;

// [
//     "lat" => 40.7607184,
//     "lng" => -73.9613766,
// ]

Alternatively, you can include the Geocodable trait in your Laravel Eloquent model to get some nice geocoding instance methods:

use Clevyr\LaravelGeocoder\Traits\Geocodable;

class MyModel extends Model
{
    use Geocodable;
}

$model = MyModel::find(1);
$coords = $model->getLatAndLong();

$model->name = 'New Name';
$model->addressIsDirty(); // false

$model->address_line_1 = '123 Foo Ln.';
$model->addressIsDirty(); // true

Modifying the Model Geolocation Fields

By default, when you use the Geocodable trait, Laravel Geocoder will default to using the following fields on your model:

  • address_line_1 (Required)
  • address_line_2
  • city (Required)
  • state (Required)
  • postal_code (Required)
  • country (Defaults to 'US')

However, you can modify these fields on a per-model basis using the following getter functions in your model:

    // Override the postal_code property with something specific to this model
    public function getGeocoderPostalCodeAttribute()
    {
        return 'zip';
    }

This would assume that there is a zip field on this model, which will then be used for this model's geolocation. Here are the full list of getter functions that you can override:

public function getGeocoderAddressLine1Attribute();
public function getGeocoderAddressLine2Attribute();
public function getGeocoderCityAttribute();
public function getGeocoderStateAttribute();
public function getGeocoderPostalCodeAttribute();
public function getGeocoderCountryAttribute();

Testing

composer test

Linting

composer analyse

Laravel Pint

Laravel Pint is an opinionated PHP code style fixer for minimalists.

./vendor/bin/pint

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 611
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固