langleyfoxall/simple-google-maps 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

langleyfoxall/simple-google-maps

Composer 安装命令:

composer require langleyfoxall/simple-google-maps

包简介

Simple PHP client for various Google Maps APIs

README 文档

README

StyleCI

This package provides a simple PHP client for various Google Maps APIs.

Installation

To install, just run the following composer command.

composer require langleyfoxall/simple-google-maps

Remember to include the vendor/autoload.php file if your framework does not do this for you.

Usage

To use Simple Google Maps, you must first create a new instance. This can be done is two ways, dependant on whether you have a standard API key, or a clientName and cryptKey (for enterprise / premium plans).

// Standard authentication:
$simpleGoogleMaps = SimpleGoogleMapsFactory::getByKey(getenv('KEY'));

// Enterprise / premium plan authentication:
$simpleGoogleMaps = SimpleGoogleMapsFactory::getByClientNameAndCryptKey(getenv('CLIENT_NAME'), getenv('CRYPT_KEY'));

Geocoding

To convert an address to a set of GPS coordinates, use the geocode method, as shown below.

$latLng = $simpleGoogleMaps->geocode('10 Downing St, Westminster, London SW1A UK');

Optionally, you can allow partial matches to be returned if your input address is not highly accurate. You can do so with the allowPartialMatches method, as shown below.

$latLng = $simpleGoogleMaps->allowPartialMatches()->geocode('test address');

The above method will return a object of type LatLong, which allows you to access the GPS coordinates as shown below.

$latitude = $latLng->lat;
$longitude = $latLng->long;

You can also calculate the distance between two LatLong objects by using the distanceTo method. The distance is returned in kilometers, and takes into account the curvature of the Earth using the Haversine formula.

$distance = $fromCoords->distanceTo($toCoords);

Reverse Geocoding

To lookup an address from a set of GPS coordinate, use the reverseGeocode method, as shown below.

$address = $simpleGoogleMaps->reverseGeocode(new LatLong(51.5033635, -0.1276248));

This method will return a string containing the address found at the specified coordinates. If no address could be found, null will be returned.

Directions

To find the directions between two points, use the directions method. The methods expects three parameters, the origin, the destination, and optionally the travel mode as defined by the TravelMode enum.

See the example usage below.

$address1 = "10 Downing St, Westminster, London SW1A UK";
$address2 = "Schott House, Drummond Rd, Stafford ST16 3EL";

$journey = $simpleGoogleMaps->directions($address1, $address2, TravelMode::DRIVING);

foreach($journey as $step) {
    echo $step->duration.' secs  ';
    echo "\t";
    echo $step->distance.' m    ';
    echo "\t";
    echo $step->description;
    echo PHP_EOL;
}

echo 'Totals: '.$journey->duration().' secs, '.$journey->distance().' km';
echo PHP_EOL;

This will produce output similar to the following.

134 secs        452 m           Head north on Whitehall / A3212 toward Horse Guards Ave May be closed at certain times or days 
203 secs        1029 m          At the roundabout, take the 1st exit onto The Mall Parts of this road may be closed at certain times or days 
121 secs        688 m           Turn right onto Constitution Hill 
34 secs         141 m           Turn left onto Duke of Wellington Pl Leaving toll zone 
20 secs         83 m            Turn right onto Grosvenor Pl 
21 secs         107 m           Slight right onto Piccadilly May be closed at certain times or days 
164 secs        1244 m          Slight left onto Park Ln / A4202 
35 secs         199 m           Slight left onto Cumberland Gate 
16 secs         68 m            Turn right onto Bayswater Rd 
92 secs         410 m           Slight left onto Edgware Rd / A5 Entering toll zone in 280 m at Upper Berkeley St Leaving toll zone in 300 m at Stourcliffe St 
48 secs         177 m           Turn right onto George St Entering toll zone 
152 secs        531 m           Turn left onto Seymour Pl 
46 secs         231 m           Turn left onto Marylebone Rd / A501 Leaving toll zone 
722 secs        9209 m          Keep right to continue on Marylebone Flyover / A40 Continue to follow A40 
708 secs        14581 m         Keep right to continue on Western Ave / A40 
4636 secs       140047 m        Keep right to continue on M40 , follow signs for M25 / Birmingham / Oxford / Beaconsfield 
49 secs         1164 m          At junction 3A , take the M42 / Railway Station / Airport exit to M1 / M6 / Birmingham (E, N & C) / Solihull / N.E.C. 
856 secs        22091 m         Merge onto M42 
14 secs         375 m           Keep right at the fork to continue on M6 Toll 
1121 secs       33363 m         Keep right at the fork to stay on M6 Toll Toll road 
756 secs        19905 m         Continue onto M6 
23 secs         206 m           At junction 14 , take the A34 exit to Stone / Stafford (N) 
103 secs        1213 m          At the roundabout, take the 3rd exit onto A34 Go through 1 roundabout 
80 secs         925 m           At the roundabout, take the 2nd exit onto Beaconside / A513 
128 secs        1550 m          Turn right onto Common Rd 
13 secs         123 m           Turn left onto Astonfields Rd 
76 secs         395 m           Turn left onto Drummond Rd Destination will be on the left 
Totals: 10371 secs, 250507 km

langleyfoxall/simple-google-maps 适用场景与选型建议

langleyfoxall/simple-google-maps 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.71k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 11 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 langleyfoxall/simple-google-maps 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 langleyfoxall/simple-google-maps 我们能提供哪些服务?
定制开发 / 二次开发

基于 langleyfoxall/simple-google-maps 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7.71k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-only
  • 更新时间: 2018-11-30