166 lines
5.6 KiB
C#
166 lines
5.6 KiB
C#
using Microsoft.AspNetCore.Http;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
|
||
using SKIT.FlurlHttpClient.Wechat.Api.Models;
|
||
using SKIT.FlurlHttpClient.Wechat.Api;
|
||
using System.Web;
|
||
|
||
using Org.BouncyCastle.Utilities;
|
||
using System.Net;
|
||
using ZR.Common;
|
||
using ZR.Model.Dto;
|
||
using Infrastructure.Model;
|
||
using System.Threading.Tasks;
|
||
using ZR.Common.Model;
|
||
|
||
namespace ZR.Admin.WebApi.Controllers
|
||
{
|
||
/// <summary>
|
||
/// webApi
|
||
/// </summary>
|
||
[Route("[controller]/[action]")]
|
||
[AllowAnonymous]
|
||
[ApiExplorerSettings(GroupName = "webapi")]
|
||
public class WebApiController : BaseController
|
||
{
|
||
private readonly TencentMapService _tencentMapService;
|
||
|
||
public WebApiController(TencentMapService tencentMapService)
|
||
{
|
||
_tencentMapService = tencentMapService;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 转换 GPS 经纬度到腾讯地图坐标
|
||
/// </summary>
|
||
/// <param name="request">坐标转换请求参数</param>
|
||
/// <returns>转换后的坐标</returns>
|
||
[HttpPost]
|
||
[Route("GetLocationTranslate")]
|
||
public async Task<IActionResult> GetLocationTranslate([FromBody] CoordinateTranslateRequest request)
|
||
{
|
||
try
|
||
{
|
||
if (request == null || string.IsNullOrWhiteSpace(request.Locations))
|
||
{
|
||
return ToResponse(ResultCode.CUSTOM_ERROR, "坐标点不能为空");
|
||
}
|
||
|
||
var result = await _tencentMapService.GetLocationTranslateAsync(request.Locations, request.Type);
|
||
return SUCCESS(result);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return ToResponse(ResultCode.CUSTOM_ERROR, ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据坐标获取地址信息
|
||
/// </summary>
|
||
/// <param name="request">地理编码请求参数</param>
|
||
/// <returns>地址信息</returns>
|
||
[HttpPost]
|
||
[Route("GetLocationGeocoder")]
|
||
public async Task<IActionResult> GetLocationGeocoder([FromBody] GeocoderRequest request)
|
||
{
|
||
try
|
||
{
|
||
if (request == null || string.IsNullOrWhiteSpace(request.Location))
|
||
{
|
||
return ToResponse(ResultCode.CUSTOM_ERROR, "坐标点不能为空");
|
||
}
|
||
|
||
var result = await _tencentMapService.GetLocationGeocoderAsync(request.Location);
|
||
return SUCCESS(result);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return ToResponse(ResultCode.CUSTOM_ERROR, ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 批量转换GPS坐标并获取地址
|
||
/// </summary>
|
||
/// <param name="request">坐标转换请求参数</param>
|
||
/// <returns>转换后的坐标和地址信息</returns>
|
||
[HttpPost]
|
||
[Route("GetLocationTranslateAndGeocoder")]
|
||
public async Task<IActionResult> GetLocationTranslateAndGeocoder([FromBody] CoordinateTranslateRequest request)
|
||
{
|
||
try
|
||
{
|
||
if (request == null || string.IsNullOrWhiteSpace(request.Locations))
|
||
{
|
||
return ToResponse(ResultCode.CUSTOM_ERROR, "坐标点不能为空");
|
||
}
|
||
|
||
var result = await _tencentMapService.GetLocationTranslateAndGeocoderAsync(request.Locations);
|
||
return SUCCESS(new
|
||
{
|
||
Location = result.Location,
|
||
Address = result.Address
|
||
});
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return ToResponse(ResultCode.CUSTOM_ERROR, ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 转换 GPS 经纬度到腾讯地图坐标 (GET方式)
|
||
/// </summary>
|
||
/// <param name="locations">坐标点,格式:lat,lng;lat,lng</param>
|
||
/// <param name="type">转换类型,默认1表示GPS坐标转腾讯坐标</param>
|
||
/// <returns>转换后的坐标</returns>
|
||
[HttpGet]
|
||
[Route("/webapi/GetLocationTranslate")]
|
||
[AllowAnonymous]
|
||
public async Task<IActionResult> GetLocationTranslateGet([FromQuery] string locations, [FromQuery] int type = 1)
|
||
{
|
||
try
|
||
{
|
||
if (string.IsNullOrWhiteSpace(locations))
|
||
{
|
||
return ToResponse(ResultCode.CUSTOM_ERROR, "坐标点不能为空");
|
||
}
|
||
|
||
var result = await _tencentMapService.GetLocationTranslateAsync(locations, type);
|
||
return SUCCESS(result);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return ToResponse(ResultCode.CUSTOM_ERROR, ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据坐标获取地址信息 (GET方式)
|
||
/// </summary>
|
||
/// <param name="location">坐标点,格式:lat,lng</param>
|
||
/// <returns>地址信息</returns>
|
||
[HttpGet]
|
||
[Route("/webapi/GetLocationGeocoder")]
|
||
[AllowAnonymous]
|
||
public async Task<IActionResult> GetLocationGeocoderGet([FromQuery] string location)
|
||
{
|
||
try
|
||
{
|
||
if (string.IsNullOrWhiteSpace(location))
|
||
{
|
||
return ToResponse(ResultCode.CUSTOM_ERROR, "坐标点不能为空");
|
||
}
|
||
|
||
var result = await _tencentMapService.GetLocationGeocoderAsync(location);
|
||
return SUCCESS(result);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return ToResponse(ResultCode.CUSTOM_ERROR, ex.Message);
|
||
}
|
||
}
|
||
}
|
||
}
|