struktal/struktal-geocoding-util
Composer 安装命令:
composer require struktal/struktal-geocoding-util
包简介
PHP library for the Nominatim Geocoding API
关键字:
README 文档
README
This is a simple PHP library to (reverse-)geocode addresses with the Nominatim API.
Legal Note: This library uses the Nominatim API. Please read the Terms of Use before using it and comply with them.
Data from OpenStreetMap is licensed under ODbL.
This library uses the Curl-Adapter library to send requests to the Nominatim API.
The Curl-Adapter library is licensed under the MIT License. (c) 2023 Struktal
Installation
To install this library, include it in your project using composer:
composer require struktal/struktal-geocoding-util
Usage
Geocode an address to coordinates
The following example shows how to geocode an address to coordinates:
<?php use struktal\Geocoding\Geocoding; $geocoding = new Geocoding(); $geocoding->setStreet("James-Franck-Ring") ->setHouseNumber("1") ->setCity("Ulm") ->setZipCode("89081") ->setCountry("Germany"); $coordinates = $geocoding->getCoordinates(); $lat = $coordinates["latitude"]; $lng = $coordinates["longitude"];
The above example will return the following coordinates:
{
"latitude": 48.4253584,
"longitude": 9.956179
}
Reverse-geocode coordinates to an address
The following example shows how to reverse-geocode coordinates to an address:
<?php use struktal\Geocoding\Geocoding; $geocoding = new Geocoding(); $geocoding->setCoordinates(48.4253584, 9.956179) ->toAddress(); $address = $geocoding->getAddress(); $street = $address["street"]; $houseNumber = $address["houseNumber"]; $city = $address["city"]; $zipCode = $address["zipCode"]; $country = $address["country"]; $formattedAddress = $geocoding->getFormattedAddress();
The above example will return the following address:
{
"street": "James-Franck-Ring",
"houseNumber": null,
"city": "Ulm",
"zipCode": "89081",
"country": "Deutschland"
}
The formatted address will also be an array with two formatting options, inline and with \n line breaks:
{
"inline": "James-Franck-Ring, 89081 Ulm, Deutschland (DE)",
"lineBreaks": "James-Franck-Ring\n89081 Ulm\nDeutschland (DE)"
}
Setting a custom user agent
You might want to set a custom user agent for your requests towards the Nominatim API to identify your application. To do that, use
<?php use struktal\Geocoding\Geocoding; Geocoding::setUserAgent("MyApplication/1.0");
If you do not set a custom user agent, the default will be
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0
Setting a custom Nominatim API URL
The public Nominatim API is very limited in the amount of requests you can send. If you want to use your own Nominatim API instance, you can set a custom URL for the API. To do that, use
<?php use struktal\Geocoding\Geocoding; Geocoding::setApiUrl("https://nominatim.mydomain.com");
struktal/struktal-geocoding-util 适用场景与选型建议
struktal/struktal-geocoding-util 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.58k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「nominatim」 「geocode」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 struktal/struktal-geocoding-util 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 struktal/struktal-geocoding-util 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 struktal/struktal-geocoding-util 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Integrates an OpenStreetMap tile proxy in TYPO3 for GDPR-compliant integration.
Nominatim Geocoding API Client
Laravel integration for Nominatim Geocoding API Client
Geolocate IP addresses using a variety of third-party services
Nominatim consumer in PHP
A PHP wrapper for the Google Maps Geocoding API v3.
统计信息
- 总下载量: 1.58k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 25
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-only
- 更新时间: 2025-06-16