承接 becklyn/postal-code-proximity 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

becklyn/postal-code-proximity

最新稳定版本:v0.1.1

Composer 安装命令:

composer require becklyn/postal-code-proximity

包简介

Calculates near postal codes (given, that a pre-generated postal code lookup database exists).

关键字:

README 文档

README

If you have a pre-generated database with a mapping of postal codes to latitude & longitude, this library will help you with searching for nearby postal codes (in a given radius).

Usage

First you need to create a query generator. The query generator is responsible for generating the SQL for loading the data from the database. You need to specify the names of the table and the columns of your postal code table.

use Becklyn\PostalCodeProximity\QueryGenerator;

$queryGenerator = new QueryGenerator($tableName, $latitudeColumn = "lat", $longitudeColumn = "lng", $postalCodeColumn = "zip");

Afterwards, you need to use a database adapter. There are already working adapters for PDO and mysqli.

use Becklyn\PostalCodeProximity\Adapter\PdoAdapter;

$pdo = new \PDO("...", "user", "password");
$databaseAdapter = new PdoAdapter($pdo, $queryGenerator);

or

use Becklyn\PostalCodeProximity\Adapter\MysqliAdapter;

$mysqli = new \mysqli("localhost", "user", "password", "dbname");
$databaseAdapter = new MysqliAdapter($mysqli, $queryGenerator);

And now you can query for nearby postal codes:

use Becklyn\PostalCodeProximity\PostalCodeLocator;

$postalCodeLocator = new PostalCodeLocator($databaseAdapter);
$postalCodeLocator->loadNearPostalCodes($postalCode, $radius, $limit = null);
  • $postalCode is the postal code, like "12345"
  • $radius is the radius in km (air-line distance)
  • $limit (optional) limit the number of results

Return value

You will receive an array of NearPostalCode

$nearPostalCode->getPostalCode();
$nearPostalCode->getDistanceInKm();

Error cases

There are two possible error case (except of exceptions directly from the databases):

  • AmbiguousPostalCodeException: if a given postal code is found multiple times in the postal code database
  • QueryException: handles all error cases originating in the database. Warning: the exception messages may contain sensitive information.

Recommended database structure

  • postal_code CHAR(5) (may vary depending on your country of origin)
  • latitude DOUBLE
  • longitude DOUBLE

You should add an unique index to the postal_code fields and indexes on latitude and longitude.

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-03-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固