chroma-x/google-datastructures
Composer 安装命令:
composer require chroma-x/google-datastructures
包简介
A PHP library providing common data structures to reflect data received from Google services.
关键字:
README 文档
README
A PHP library to query Google's Places service for querying locations and addresses and getting details by Places ID.
Installation
{
"require": {
"chroma-x/google-datastructures": "*"
}
}
Usage
Autoloading and namesapce
require_once('path/to/vendor/autoload.php');
GeoLocation data structures
Reading a Google Places or Google Geocoder result
See PHP Google Places Suite or PHP Google Geocoder for example libraries using these datastructures.
Attention: Plaese note that all getter methods on the GeoLocationAddress return a GeoLocationAddressComponent instance or null. For preventing calls on non-objects the GeoLocationAddress class provides methods to check whether the address components exists.
// Retrieving a query result as ChromaX\GooglePlacesSuite\GooglePlacesDetailResult instance
$googlePlacesDetailQuery = new GooglePlacesDetailQuery();
$googlePlacesDetailQuery
->setApiKey($this->googlePlacesApiKey)
->query('GOOGLE_PLACES_ID');
$queryResult = $googlePlacesDetailQuery->getResult();
// Retieving address information as ChromaX\GoogleDataStructure\GeoLocation\GeoLocationAddress
if($queryResult->hasAddress()) {
if ($queryResult->getAddress()->hasStreetName()) {
// Returns 'Lornsenstraße'
$addressStreetShort = $queryResult->getAddress()->getStreetName()->getShortName();
// Returns 'Lornsenstraße'
$addressStreetLong = $queryResult->getAddress()->getStreetName()->getLongName();
}
if ($queryResult->getAddress()->hasStreetNumber()) {
// Returns '43'
$addressStreetNumberShort = $queryResult->getAddress()->getStreetNumber()->getShortName();
// Returns '43'
$addressStreetNumberLong = $queryResult->getAddress()->getStreetNumber()->getLongName();
}
if ($queryResult->getAddress()->hasPostalCode()) {
// Returns '24105'
$addressPostalCodeShort = $queryResult->getAddress()->getPostalCode()->getShortName();
// Returns '24105'
$addressPostalCodeLong = $queryResult->getAddress()->getPostalCode()->getLongName();
}
if ($queryResult->getAddress()->hasCity()) {
// Returns 'KI'
$addressCityShort = $queryResult->getAddress()->getCity()->getShortName();
// Returns 'Kiel'
$addressCityLong = $queryResult->getAddress()->getCity()->getLongName();
}
if ($queryResult->getAddress()->hasArea()) {
// Returns 'Ravensberg - Brunswik - Düsternbrook'
$addressAreaShort = $queryResult->getAddress()->getArea()->getShortName();
// Returns 'Ravensberg - Brunswik - Düsternbrook'
$addressAreaLong = $queryResult->getAddress()->getArea()->getLongName();
}
if ($queryResult->getAddress()->hasProvince()) {
// Returns 'SH'
$addressProvinceShort = $queryResult->getAddress()->getProvince()->getShortName();
// Returns 'Schleswig-Holstein'
$addressProvinceLong = $queryResult->getAddress()->getProvince()->getLongName();
}
if ($queryResult->getAddress()->hasCountry()) {
// Returns 'DE'
$addressCountryShort = $queryResult->getAddress()->getCountry()->getShortName();
// Returns 'Germany'
$addressCountryLong = $queryResult->getAddress()->getCountry()->getLongName();
}
}
// Retieving address information as ChromaX\GoogleDataStructure\GeoLocation\GeoLocationGeometry
if ($queryResult->hasGeometry()) {
if ($queryResult->getGeometry()->hasLocation()) {
// Returns 54.334123
$geometryLocationLatitude = $queryResult->getGeometry()->getLocation()->getLatitude();
// Returns 10.1364007
$geometryLocationLatitude = $queryResult->getGeometry()->getLocation()->getLongitude();
}
if ($queryResult->getGeometry()->hasViewport()) {
// Returns 54.335471980291
$geometryLocationLatitude = $queryResult->getGeometry()->getViewport()->getNortheast()->getLatitude();
// Returns 10.137749680292
$geometryLocationLatitude = $queryResult->getGeometry()->getViewport()->getNortheast()->getLongitude();
// Returns 54.332774019708
$geometryLocationLatitude = $queryResult->getGeometry()->getViewport()->getSouthwest()->getLatitude();
// Returns 10.135051719708
$geometryLocationLatitude = $queryResult->getGeometry()->getViewport()->getSouthwest()->getLongitude();
}
if ($queryResult->getGeometry()->hasAccessPoints()) {
for ($i = 0; $i < $queryResult->getGeometry()->countAccessPoints(); $i++) {
// Returns 54.335471980291
$geometryAccessPointLatitude = $queryResult->getGeometry()->getAccessPointAt($i)->getLatitude();
// Returns 10.137749680292
$geometryAccessPointLatitude = $queryResult->getGeometry()->getAccessPointAt($i)->getLongitude();
}
}
}
if ($queryResult->hasGooglePlacesId()) {
// Retrieving the Google Places information from the query result
// Returns 'ChIJ_zNzWmpWskcRP8DWT5eX5jQ'
$googlePlacesId = $queryResult->getGooglePlacesId();
}
Contribution
Contributing to our projects is always very appreciated.
But: please follow the contribution guidelines written down in the CONTRIBUTING.md document.
License
PHP Google Places Suite is under the MIT license.
chroma-x/google-datastructures 适用场景与选型建议
chroma-x/google-datastructures 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.41k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 01 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「google」 「data structure」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chroma-x/google-datastructures 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chroma-x/google-datastructures 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chroma-x/google-datastructures 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Simple, immutable data structures
Adds the EDTF data type to Wikibase
A simple library that allows transform any kind of data to native php data or whatever
Extension provide very simply use enum for models (and others) in yii2
TYPO3 extension providing content elements powered by gridelements and bootstrap. Available elements: container, columns, tabs, accordion, tile unit and card.
统计信息
- 总下载量: 19.41k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-18