mtsung/mapsapi

从jyun/mapsapi迁移

1.0.1 2024-01-22 04:34 UTC

This package is auto-updated.

Last update: 2024-09-22 05:58:00 UTC


README

jyun/mapsapi迁移

支持Laravel 10

安装

在專案中執行下方指令

composer require mtsung/mapsapi

安装好后即可在專案内使用

use Mtsung\Mapsapi\TwddMap\Geocoding;

配置

在專案中如使用Mysql, Mongo, Map8, GoogleMap,都須分别配置.env,请参照

目前Mongo因为数据太多错误决定停止使用

Mysql, Mongo        # 自行配置
MAPSAPI_GOOGLE_API_KEY=""     # 圖霸 KEY
MAPSAPI_MAP8_API_KEY=""   # Google API KEY
MAPSAPI_ENABLE_TWDD_MONGO=false

使用方法

路线API

use Mtsung\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 (timeout = 2s)
  • reverseGeocode: Mongo -> Map8 -> GoogleMap (timeout = 2s)

注意事项

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

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

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

API统一返回格式