yipikai/geolocation-bundle

此扩展包通过api adress.gouv.fr检索邮政地址的纬度和经度

v1.0.1 2024-07-15 14:19 UTC

This package is auto-updated.

Last update: 2024-09-24 06:38:21 UTC


README

Minimum PHP Version Latest Stable Version Total Downloads License

安装扩展包

您可以使用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赞助。