Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/ESCloudSDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ESCloud\SDK\Service\DrpService;
use ESCloud\SDK\Service\ESopService;
use ESCloud\SDK\Service\InspectionService;
use ESCloud\SDK\Service\MapService;
use ESCloud\SDK\Service\MobileService;
use ESCloud\SDK\Service\MpService;
use ESCloud\SDK\Service\NotificationService;
Expand Down Expand Up @@ -189,6 +190,14 @@ public function getPlatformNewsService()
return $this->getService('PlatformNews');
}

/**
* @return MapService
*/
public function getMapService()
{
return $this->getService('Map', true);
}

/**
* 根据服务名获得服务实例
*
Expand Down
98 changes: 98 additions & 0 deletions src/Service/MapService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace ESCloud\SDK\Service;

use ESCloud\SDK\Exception\SDKException;

class MapService extends BaseService
{
protected $host = 'map.vviioo.com';

protected $service = 'Map';

/**
* 将GPS坐标转换为百度经纬度坐标
*
* @param float $longitude
* @param float $latitude
* @return array|mixed
* @throws SDKException
* @throws \ESCloud\SDK\Exception\ResponseException
* @throws \ESCloud\SDK\HttpClient\ClientException
*/
public function wgs84ToBd09(float $longitude, float $latitude)
{
return $this->request('POST', '/api/v1/location/wgs84ToBd09', ['longitude' => $longitude, 'latitude' => $latitude]);
}

/**
* 将高德/腾讯坐标转换为百度经纬度坐标
*
* @param float $longitude
* @param float $latitude
* @return array|mixed
* @throws SDKException
* @throws \ESCloud\SDK\Exception\ResponseException
* @throws \ESCloud\SDK\HttpClient\ClientException
*/
public function gcj02ToBd09(float $longitude, float $latitude)
{
return $this->request('POST', '/api/v1/location/gcj02ToBd09', ['longitude' => $longitude, 'latitude' => $latitude]);
}

/**
* 计算一个中心点与其他一系列坐标点的距离
*
* @param float $longitude
* @param float $latitude
* @param array $targets
* @return array|mixed
* @throws SDKException
* @throws \ESCloud\SDK\Exception\ResponseException
* @throws \ESCloud\SDK\HttpClient\ClientException
*/
public function distances(float $longitude, float $latitude, array $targets)
{
if (empty($targets)) {
throw new SDKException('Targets is empty.');
}
foreach ($targets as $target) {
if (empty($target) || !is_array($target) || !isset($target['longitude']) || !isset($target['latitude'])) {
throw new SDKException('Targets is invalid.');
}
}

return $this->request('POST', '/api/v1/location/distances', [
'origin' => ['longitude' => $longitude, 'latitude' => $latitude],
'targets' => $targets,
]);
}

/**
* 获取地图服务状态
*
* @return array|mixed
* @throws SDKException
* @throws \ESCloud\SDK\Exception\ResponseException
* @throws \ESCloud\SDK\HttpClient\ClientException
*/
public function status()
{
return $this->request('GET', '/api/v1/tenant/status');
}

/**
* 获取地图服务代理URL
*
* @return string
*/
public function proxyUrl()
{
return '//'.$this->host.'/proxy/'.$this->getProxyToken();
}

public function getProxyToken()
{
return str_replace('Bearer ', '', $this->auth->makeRequestAuthorization('', '', 3600, true, $this->service));
}
}