greeneh/postcode

此包的最新版本(0.0.1)没有可用的许可信息。

跨不同提供商进行邮编的统一搜索。

0.0.1 2014-09-24 08:31 UTC

This package is auto-updated.

Last update: 2024-09-14 02:58:36 UTC


README

简单搜索邮编以获取地理信息。支持各种API提供商和统一地址/输出格式。

安装

使用 composer - 添加到您的 requires 部分

  • "greeneh/postcode": "~0.0.1"

Laravel 特定

将以下内容添加到您的 config/app.php

  1. providers 数组

'Greeneh\Postcode\PostcodeServiceProvider',

  1. aliases 数组

'Postcode' => 'Greeneh\Postcode\Facades\Postcode',

使用方法

从邮编获取地理信息

Postcode::search('E16 1FW')

使用 Google API 提供商的结果

object(Greeneh\Postcode\Address)[282]
  protected 'fillable' => 
    array (size=6)
      0 => string 'town' (length=4)
      1 => string 'city' (length=4)
      2 => string 'county' (length=6)
      3 => string 'latitude' (length=8)
      4 => string 'longitude' (length=9)
      5 => string 'source' (length=6)
  protected 'attributes' => 
    array (size=6)
      'town' => null
      'city' => string 'London' (length=6)
      'county' => string 'Greater London' (length=14)
      'latitude' => float 51.5166391
      'longitude' => float 0.0210837
      'source' => 
        object(stdClass)[246]
          public 'results' => 
            array (size=1)
              0 => 
                object(stdClass)[250]
                  public 'address_components' => 
                    array (size=6)
                      0 => 
                        object(stdClass)[232]
                          public 'long_name' => string 'E16 1FW' (length=7)
                          public 'short_name' => string 'E16 1FW' (length=7)
                          public 'types' => 

从邮编获取经纬度

Postcode::getCoordinates('E16 1FW')

结果

array (size=2)
  'latitude' => float 51.6359841
  'longitude' => float 0.2919168