jyun/mapsapi

这是地理相关的第三方API集成

1.0.18 2024-05-20 07:14 UTC

This package is auto-updated.

Last update: 2024-09-20 07:57:53 UTC


README

在项目中执行以下命令

composer require jyun/mapsapi

安装完成后即可在项目中使用

use Jyun\Mapsapi\TwddMap\Geocoding;

配置文件

在项目中使用 Mysql, Mongo, Map8, GoogleMap 等都需要单独配置 .env,请参考

目前Mongo由于数据过多错误已决定停止使用

Mysql, Mongo        # 自行配置
MAP8_API_KEY=""     # 圖霸 KEY
GOOGLE_API_KEY=""   # Google API KEY

路线API

use Jyun\Mapsapi\TwddMap\Directions;

/**
 * Directions
 *
 * @param $origin
 * @param $destination
 * @param $mode ['driving', 'walking', 'bicycling'], default='driving'
 * @return array|mixed
*/
$directions = Directions::directions('25.0097038,121.4401783', '25.0108898,121.4346963');

地理编码API

源代码顺序

  • geocode: Map8 -> GoogleMap (超时时间 = 2秒)
  • reverseGeocode: Mongo -> Map8 -> GoogleMap (超时时间 = 2秒)

注意事项

  • Map8超出台湾地区会返回空值,但设计上会继续查询GoogleMap
  • 源代码查询时可能返回空值,所以zip, city_id, district_id有可能为null
use Jyun\Mapsapi\TwddMap\Geocoding;

$geocode = Geocoding::geocode('台北市內湖區瑞光路335號');

$reverseGeocode = Geocoding::reverseGeocode('25.0396476673,121.505226616');

API统一返回格式