-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
207 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using NewLife.Data; | ||
using NewLife.Map; | ||
using Xunit; | ||
|
||
namespace XUnitTest; | ||
|
||
public class AMapTests | ||
{ | ||
private readonly AMap _map; | ||
public AMapTests() => _map = new AMap { AppKey = "2aada76e462af71e1b67ba1df22d0fa4" }; | ||
|
||
[Fact] | ||
public async void Geocoder() | ||
{ | ||
var addr = "上海中心大厦"; | ||
var map = _map; | ||
//var rs = await map.GetGeocoderAsync(addr); | ||
|
||
//Assert.NotNull(rs); | ||
//Assert.True(rs.ContainsKey("location")); | ||
|
||
var ga = await map.GetGeoAsync(addr, null, null, false); | ||
|
||
Assert.NotNull(ga); | ||
Assert.Equal(121.505366, ga.Location.Longitude); | ||
Assert.Equal(31.23351, ga.Location.Latitude); | ||
Assert.Equal("上海市浦东新区上海中心大厦", ga.Address); | ||
//Assert.True(ga.Confidence > 0); | ||
|
||
ga = await map.GetGeoAsync(addr, null, null, true); | ||
|
||
Assert.NotNull(ga); | ||
Assert.Equal(121.505366, ga.Location.Longitude); | ||
Assert.Equal(31.23351, ga.Location.Latitude); | ||
Assert.Equal("上海市浦东新区陆家嘴街道上海中心大厦上海中心·上海之品商场", ga.Address); | ||
Assert.Equal("上海市浦东新区陆家嘴街道银城中路501号东16米", ga.Title); | ||
Assert.Equal(310115, ga.Code); | ||
Assert.Equal(310115005, ga.Towncode); | ||
} | ||
|
||
[Fact] | ||
public async void GetDistanceAsync() | ||
{ | ||
var points = new List<GeoPoint> | ||
{ | ||
new() { Longitude = 121.51199904625513, Latitude = 31.239184419374944 }, | ||
new() { Longitude = 114.21892734521, Latitude = 29.575429778924 } | ||
}; | ||
|
||
var map = _map; | ||
var drv = await map.GetDistanceAsync(points[0], points[1], "wgs84", 0); | ||
|
||
Assert.NotNull(drv); | ||
Assert.Equal(851357, drv.Distance); | ||
Assert.True(Math.Abs(32190 - drv.Duration) < 600); | ||
} | ||
|
||
//[Fact] | ||
//public async void ConvertAsync() | ||
//{ | ||
// var points = new List<GeoPoint> | ||
// { | ||
// new() { Longitude = 121.51199904625513, Latitude = 31.239184419374944 }, | ||
// new() { Longitude = 114.21892734521, Latitude = 29.575429778924 } | ||
// }; | ||
|
||
// var map = _map; | ||
// var points2 = await map.ConvertAsync(points, "wgs84", "gcj02"); | ||
|
||
// Assert.NotNull(points2); | ||
|
||
// Assert.Equal(points.Count, points2.Count); | ||
// Assert.True(points2[0].Longitude > 0); | ||
// Assert.True(points2[0].Latitude > 0); | ||
//} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Text; | ||
using NewLife; | ||
using NewLife.Data; | ||
using NewLife.Http; | ||
using NewLife.Map; | ||
using Xunit; | ||
|
||
namespace XUnitTest; | ||
|
||
public class WeMapTests | ||
{ | ||
private readonly WeMap _map; | ||
public WeMapTests() => _map = new WeMap { AppKey = "YGEBZ-BDCCX-AJG4X-ZUH6W-MESMV-P2BFF" }; | ||
|
||
[Fact] | ||
public async void Geocoder() | ||
{ | ||
var addr = "上海中心"; | ||
var map = _map; | ||
//var rs = await map.GetGeocoderAsync(addr); | ||
|
||
//Assert.NotNull(rs); | ||
//Assert.True(rs.ContainsKey("location")); | ||
|
||
var ga = await map.GetGeoAsync(addr, null, null, false); | ||
|
||
Assert.NotNull(ga); | ||
Assert.Equal(121.505406, ga.Location.Longitude); | ||
Assert.Equal(31.233501, ga.Location.Latitude); | ||
//Assert.Null(ga.Address); | ||
Assert.True(ga.Confidence > 0); | ||
|
||
ga = await map.GetGeoAsync(addr, null, null, true); | ||
|
||
Assert.NotNull(ga); | ||
Assert.Equal(121.505406, ga.Location.Longitude); | ||
Assert.Equal(31.233501, ga.Location.Latitude); | ||
Assert.Equal("上海市浦东新区陆家嘴银城中路501号", ga.Address); | ||
Assert.Equal("上海市浦东新区花园石桥路", ga.Title); | ||
Assert.Equal(310115, ga.Code); | ||
//Assert.Equal(310115005, ga.Towncode); | ||
} | ||
|
||
[Fact] | ||
public async void GetDistanceAsync() | ||
{ | ||
var points = new List<GeoPoint> | ||
{ | ||
new() { Longitude = 121.51199904625513, Latitude = 31.239184419374944 }, | ||
new() { Longitude = 114.21892734521, Latitude = 29.575429778924 } | ||
}; | ||
|
||
var map = _map; | ||
var drv = await map.GetDistanceAsync(points[0], points[1], "wgs84", 0); | ||
|
||
Assert.NotNull(drv); | ||
Assert.Equal(851907, drv.Distance); | ||
Assert.True(Math.Abs(37020 - drv.Duration) < 600); | ||
} | ||
|
||
//[Fact] | ||
//public async void ConvertAsync() | ||
//{ | ||
// var points = new List<GeoPoint> | ||
// { | ||
// new() { Longitude = 121.51199904625513, Latitude = 31.239184419374944 }, | ||
// new() { Longitude = 114.21892734521, Latitude = 29.575429778924 } | ||
// }; | ||
|
||
// var map = _map; | ||
// var points2 = await map.ConvertAsync(points, "wgs84", "gcj02"); | ||
|
||
// Assert.NotNull(points2); | ||
|
||
// Assert.Equal(points.Count, points2.Count); | ||
// Assert.True(points2[0].Longitude > 0); | ||
// Assert.True(points2[0].Latitude > 0); | ||
//} | ||
} |