dynamic/silverstripe-geocoder
Composer 安装命令:
composer require dynamic/silverstripe-geocoder
包简介
SilverStripe wrapper for Geocoder
README 文档
README
SilverStripe wrapper for Geocoder
Requirements
- PHP: ^8.3
- silverstripe/recipe-core: ^6
- dynamic/silverstripe-country-dropdown-field: ^3
- geocoder-php/google-maps-provider: ^4.7
- guzzlehttp/guzzle: ^7.4
- php-http/guzzle7-adapter: ^1.0
- php-http/message: ^1.13
Installation
composer require dynamic/silverstripe-geocoder
Features
- Address Geocoding: Automatically convert addresses to latitude/longitude coordinates using Google Maps Geocoding API
- Address Data Extension: Adds comprehensive address fields (Address, City, State, PostalCode, Country, Lat, Lng) to any DataObject
- Distance Calculation: Calculate and filter DataObjects by distance from a given address
- Static Map Generation: Generate static Google Maps images with custom styling and markers
- Country Dropdown Integration: Includes country selection field with international support
- Flexible Configuration: Disable geocoding per DataObject, customize map styles, and use custom marker icons
License
See License
Example usage
Getting Started
in mysite/_config/config.yml, apply the DataExtensions to your DataObject:
SilverStripe\ORM\DataObject: extensions: - Dynamic\SilverStripeGeocoder\AddressDataExtension - Dynamic\SilverStripeGeocoder\DistanceDataExtension
Google API Keys
You'll also need to set two Google API keys. Each key needs to have specific API libraries enabled:
geocoder_api_key- Geocoding API
map_api_key- Maps JavaScript API
- Maps Static API
This is primarily due to the restriction rules on Google API keys. The Geocoding key should be tied to the webserver's public IP, while the Maps API needs to be restricted to the website's domain name. Restriction rules help to prevent unauthorized users to use your keys, which can quickly use up your API requests quota.
Dynamic\SilverStripeGeocoder\GoogleGeocoder: geocoder_api_key: 'your-key-here' map_api_key: 'your-key-here'
Documentation
AddressDataExtension
The AddressDataExtension adds Address, Address2, City, State, PostalCode, Country, Lat, and Lng fields.
The Lat and Lng fields are read only in the cms and are automatically generated on write.
Geocoding can be disabled on a model basis by setting disable_geocoding to true.
SilverStripe\ORM\DataObject: disable_geocoding: true
Static Map Image
Using $AddressMap in a template will render the map.
$AddressMap also has options to easily modify the width, height, and scale of the map. $AddressMap(320, 240, 1)
Map Style
The map can be styled by adding a mapStyle.json in any of the following folders in a theme:
client/dist/js/
client/dist/javascript/
dist/js/
dist/javascript/
src/javascript/thirdparty
js/
javascript/
Styles can be generated using an online service like Styling Wizard: Google Maps APIs
Marker Image
This does not work on local due to google needing to download the image off the server.
A custom marker image can be used to match the style of the map in about the same way as the style.
An image named mapIcon with an extension of png, jpg, jpeg, or gif can be put in any of the following folders in a theme:
client/dist/img/
client/dist/images/
dist/img/
dist/images/
img/
images/
DistanceDataExtension
The DistanceDataExtension should be used in conjunction with the AddressDataExtension.
The only time it is viable by itself is if the extended DataObject has Lat and Lng fields.
The DistanceDataExtension will add a pseudo field for distance away from an address to a DataObject.
The address to check the distance to is from the current controller initially.
This can be changed by implementing updateAddressValue($address) on the DataObject or an extension.
/** * Always get the distance from Neuschwanstein Castle */ public function updateAddressValue(&$address) { $address = 'Neuschwansteinstraße 20, 87645 Schwangau, Germany'; }
Upgrading from version 3
SilverStripe Geocoder v4.0 is compatible with SilverStripe 6. Key changes:
- Updated to SilverStripe CMS 6
- Requires PHP 8.3 or higher
- Updated
dynamic/silverstripe-country-dropdown-fieldfrom ^2 to ^3 (SS6 compatible) - Internal extension namespace changes (ORM → Core\Extension); no changes required in user code
For details on the SilverStripe 6 upgrade, see the SilverStripe 6 upgrade guide.
Maintainers
Bugtracker
Bugs are tracked in the issues section of this repository. Before submitting an issue please read over existing issues to ensure yours is unique.
If the issue does look like a new bug:
- Create a new issue
- Describe the steps required to reproduce your issue, and the expected outcome. Unit tests, screenshots and screencasts can help here.
- Describe your environment as detailed as possible: SilverStripe version, Browser, PHP version, Operating System, any installed SilverStripe modules.
Please report security issues to the module maintainers directly. Please don't file security issues in the bugtracker.
Development and contribution
If you would like to make contributions to the module please ensure you raise a pull request and discuss with the module maintainers.
dynamic/silverstripe-geocoder 适用场景与选型建议
dynamic/silverstripe-geocoder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 48.53k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 12 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「geocoding」 「geocoder」 「silverstripe」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dynamic/silverstripe-geocoder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dynamic/silverstripe-geocoder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dynamic/silverstripe-geocoder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Maps in minutes. Powered by the Google Maps API.
Yii2 map input widget. Allows you to select geographcal coordinates via a human-friendly inteface.
GISCO Geocoding Provider for Geocoder PHP.
Integration of Geocoder into Symfony2
Laravel integration for Nominatim Geocoding API Client
统计信息
- 总下载量: 48.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 13
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2016-12-16