niborb / postcode-api-nu
邮编 API 库 (postcodeapi.nu)
dev-master
2016-03-20 11:41 UTC
Requires
- php: >=5.3.3
- guzzle/guzzle: ~3.7
- symfony/console: 2.4.*
Requires (Dev)
- phpspec/phpspec: 2.0.*@dev
This package is not auto-updated.
Last update: 2024-09-25 11:16:44 UTC
README
PHP 库用于免费荷兰邮编 API NU 服务:postcodeapi.nu
安装
您必须从 postcodeapi.nu 请求一个 API 密钥才能使用邮编服务。(它是免费的!)
您可以使用 Composer 安装库。
composer.phar require "niborb/postcode-api-nu=dev-master"
该库需要一个 PSR-0 加载器,例如 Composer 提供的那个。
用法
<?php require 'vendor/autoload.php'; use Niborb\PostcodeAPI\PostcodeAPI; $apiKey = '###YOUR-POSTCODE-API-NU-KEY###'; $service = new PostCodeAPI($apiKey); // postalcode + housenumber $address = $service->getAddressByPostalcodeAndHouseNumber('5041EB', 21); echo $address . "\n\n"; // only by postalcode $address = $service->getAddressByPostalcode('5041EB'); echo $address . "\n\n"; // by geo latitude and longitude $address = $service->getAddressByLatitudeAndLongitude(51.5664, 5.07718); echo $address . "\n\n";
输出
Street: Wilhelminapark 21
Postalcode: 5041EB
Town: Tilburg
Municipality: Tilburg
Province: Noord-Brabant
Latitude: 51,5664
Longitude: 5,07718
Street: Wilhelminapark
Postalcode: 5041EB
Town: Tilburg
Municipality: Tilburg
Province: Noord-Brabant
Latitude: 51,5663166667
Longitude: 5,0771925
Street: Wilhelminapark 21
Postalcode: 5041EB
Town: Tilburg
Municipality: Tilburg
Province: Noord-Brabant
Latitude: 51,5664
Longitude: 5,07718
PHPSpec
该库包含 PHPSpec 测试(./spec)。克隆仓库并运行
vendor/bin/phpspec run