yipikai / geolocation-bundle
此扩展包通过api adress.gouv.fr检索邮政地址的纬度和经度
v1.0.1
2024-07-15 14:19 UTC
Requires
- php: ^7.4 || ^8.0 || ^8.1 || ^8.2
- symfony/http-client: ^5.4 || ^6.4
- symfony/monolog-bundle: ^3.8
- symfony/property-access: ^5.4 || ^6.4
README
安装扩展包
您可以使用Composer安装它
composer require yipikai/geolocation-bundle
此扩展包使用adresse.data.gouv.fr的API
文档
通过邮政地址检索坐标
使用事件调度器
$geolocationEvent = new GeolocationEvent(); $geolocationEvent->setAddress("134 route de Vertou 44200 Nantes"); $eventDispatcher->dispatch($geolocationEvent, GeolocationEvent::EVENT_YIPIKAI_GEOLOCATION_RETRIEVE); // Get Latitude $latitude = $geolocationEvent->getLatitude(); // Get Longitude $longitude = $geolocationEvent->getLongitude();
使用服务容器
$coordinates = $this->container->get('yipikai.geolocation')->retrieveByAddress("134 route de Vertou 44200 Nantes"); /** * $coordinates = array:2 [ * "latitude" => 47.186543 * "longitude" => -1.528056 * ] */
使用对象检索坐标
... use Yipikai\GeolocationBundle\Doctrine\Mapping as Geolocation; class Object { ... /** * @var string|null * @Geolocation\AddressStreet() */ protected ?string $addressStreet = null; /** * @var string|null * @Geolocation\AddressCity() */ protected ?string $city = null; /** * @var string|null * @Geolocation\AddressPostalCode() */ protected ?string $postalCode = null; /** * @var string|null * @Geolocation\CoordinateLatitude() */ protected ?string $latitude = null; /** * @var string|null * @Geolocation\CoordinateLongitude() */ protected ?string $longitude = null; ... }
使用事件调度器
$object = new Object(); $object->setAddressStreet("134 route de Vertou"); $object->setCity("Nantes"); $object->setPostalCode("44200"); $geolocationEvent = new GeolocationEvent(); $geolocationEvent->setObject($object); // hydrate auto latitude and longitude in to object $geolocationEvent->setHydrateObject(true); $eventDispatcher->dispatch($geolocationEvent, GeolocationEvent::EVENT_YIPIKAI_GEOLOCATION_RETRIEVE); // Get Latitude $latitude = $geolocationEvent->getLatitude(); // Get Longitude $longitude = $geolocationEvent->getLongitude(); // Get Address $address = $geolocationEvent->getAddress();
使用服务容器
$object = new Object(); $object->setAddressStreet("134 route de Vertou"); $object->setCity("Nantes"); $object->setPostalCode("44200"); $coordinates = $this->geolocation->retrieveByObject($object, true); // This second var is hydrate auto $coordinates = $this->container->get('yipikai.geolocation')->retrieveByAddress("134 route de Vertou 44200 Nantes"); /** * $coordinates = array:2 [ * "latitude" => 47.186543 * "longitude" => -1.528056, * "address" => "134 route de Vertou 44200 Nantes" * ] */
提交信息
提交信息必须遵循常规提交规范。允许以下类型
update
: 更新fix
: 错误修复feat
: 新功能docs
: 文档更改spec
: 规范更改test
: 测试相关更改perf
: 性能优化
示例
update : Something
fix: Fix something
feat: Introduce X
docs: Add docs for X
spec: Z disambiguation
许可和版权
查看许可证文件
致谢
由Matthieu Beurel创建。由Yipikai Studio赞助。