Skip to content

Commit

Permalink
[feat] 增加GeoPoint到GeoHash之间的编解码
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Oct 23, 2023
1 parent ce33fce commit 0553122
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
6 changes: 3 additions & 3 deletions MapApi/MapApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NewLife.Cube.Core" Version="5.5.2023.601" />
<PackageReference Include="NewLife.Stardust.Extensions" Version="2.9.2023.801" />
<PackageReference Include="NewLife.XCode" Version="11.9.2023.801" />
<PackageReference Include="NewLife.Cube.Core" Version="5.6.2023.1016" />
<PackageReference Include="NewLife.Stardust.Extensions" Version="2.9.2023.1001" />
<PackageReference Include="NewLife.XCode" Version="11.10.2023.1012" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 16 additions & 0 deletions NewLife.Map/Data/GeoPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ public GeoPoint(String location)
}
#endregion

#region 方法
/// <summary>编码坐标点为GeoHash字符串</summary>
/// <param name="level">字符个数。默认9位字符编码,精度2米</param>
/// <returns></returns>
public String Encode(Int32 level = 9) => GeoHash.Encode(Longitude, Latitude, level);

/// <summary>解码GeoHash字符串为坐标点</summary>
/// <param name="hash"></param>
/// <returns></returns>
public static GeoPoint Decode(String hash)
{
var p = GeoHash.Decode(hash);
return new GeoPoint(p.Longitude, p.Latitude);
}
#endregion

/// <summary>已重载</summary>
/// <returns></returns>
public override String ToString() => $"{Longitude},{Latitude}";
Expand Down
8 changes: 3 additions & 5 deletions NewLife.Map/Map.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using NewLife.Caching;
using NewLife.Data;
using NewLife.Data;
using NewLife.Log;
using NewLife.Reflection;
using NewLife.Security;
using NewLife.Serialization;
using NewLife.Threading;

Expand Down Expand Up @@ -90,7 +88,7 @@ public class Map : DisposeBase
public String? LastString { get; private set; }

/// <summary>最后结果</summary>
public IDictionary<String, Object>? LastResult { get; private set; }
public IDictionary<String, Object?>? LastResult { get; private set; }

/// <summary>收到异常响应时是否抛出异常</summary>
public Boolean ThrowException { get; set; }
Expand Down Expand Up @@ -157,7 +155,7 @@ public virtual async Task<String> GetStringAsync(String url)

LastResult = rs;

return (T)rs;
return rs == null ? null : JsonHelper.Convert<T>(rs);
}
#endregion

Expand Down
4 changes: 2 additions & 2 deletions NewLife.Map/NewLife.Map.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NewLife.Core" Version="10.5.2023.801" />
<PackageReference Include="NewLife.Stardust" Version="2.9.2023.801" />
<PackageReference Include="NewLife.Core" Version="10.6.2023.1001" />
<PackageReference Include="NewLife.Stardust" Version="2.9.2023.1001" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NewLife.Core" Version="10.5.2023.801" />
<PackageReference Include="NewLife.Stardust.Extensions" Version="2.9.2023.801" />
<PackageReference Include="NewLife.XCode" Version="11.9.2023.801" />
<PackageReference Include="xunit.assert" Version="2.5.0" />
<PackageReference Include="NewLife.Core" Version="10.6.2023.1001" />
<PackageReference Include="NewLife.Stardust.Extensions" Version="2.9.2023.1001" />
<PackageReference Include="NewLife.XCode" Version="11.10.2023.1012" />
<PackageReference Include="xunit.assert" Version="2.5.3" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions XUnitTest/XUnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="NewLife.Core" Version="10.5.2023.801" />
<PackageReference Include="NewLife.UnitTest" Version="1.0.2023.718" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="NewLife.Core" Version="10.6.2023.1001" />
<PackageReference Include="NewLife.UnitTest" Version="1.0.2023.905" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit 0553122

Please sign in to comment.