160 lines
3.5 KiB
Go
160 lines
3.5 KiB
Go
package autonavi
|
||
|
||
import (
|
||
"testing"
|
||
|
||
"git.rosy.net.cn/baseapi"
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
|
||
"go.uber.org/zap"
|
||
)
|
||
|
||
var (
|
||
autonaviAPI *API
|
||
sugarLogger *zap.SugaredLogger
|
||
)
|
||
|
||
func init() {
|
||
logger, _ := zap.NewDevelopment()
|
||
sugarLogger = logger.Sugar()
|
||
baseapi.Init(sugarLogger)
|
||
|
||
autonaviAPI = New("ef64f638f31e05cb7bde28790f7309fe")
|
||
}
|
||
|
||
func TestCoordinateConvert(t *testing.T) {
|
||
gpsLng := 116.481499
|
||
gpsLat := 39.990475
|
||
desiredLng := 116.487585177952
|
||
desiredLat := 39.991754014757
|
||
lng, lat, err := autonaviAPI.CoordinateConvert(gpsLng, gpsLat, CoordSysGPS)
|
||
if err != nil {
|
||
t.Fatalf("TestCoordinateConvert failed with error:%v", err)
|
||
} else {
|
||
if lng != desiredLng || lat != desiredLat {
|
||
t.Fatal("CoordinateConvert result is wrong")
|
||
}
|
||
}
|
||
}
|
||
|
||
func TestGetCoordinateDistrictCode(t *testing.T) {
|
||
dongguanLng := 113.703870
|
||
dongguanLat := 22.833210
|
||
districtCode := autonaviAPI.GetCoordinateDistrictCode(dongguanLng, dongguanLat)
|
||
if districtCode != 9441900 {
|
||
t.Fatalf("TestGetCoordinateCodes failed")
|
||
} else {
|
||
t.Log(districtCode)
|
||
}
|
||
|
||
cdgxWuhouLng := 104.052971
|
||
cdgxWuhouLat := 30.576076
|
||
districtCode = autonaviAPI.GetCoordinateDistrictCode(cdgxWuhouLng, cdgxWuhouLat)
|
||
if districtCode != 510107 {
|
||
t.Fatalf("TestGetCoordinateCodes failed")
|
||
} else {
|
||
t.Log(districtCode)
|
||
}
|
||
|
||
districtCode = autonaviAPI.GetCoordinateDistrictCode(0, 0)
|
||
if districtCode != 0 {
|
||
t.Fatalf("TestGetCoordinateCodes failed")
|
||
} else {
|
||
t.Log(districtCode)
|
||
}
|
||
}
|
||
|
||
func TestGetCoordinateTownInfo(t *testing.T) {
|
||
dongguanLng := 120.74567
|
||
dongguanLat := 31.69742
|
||
townName, townCode := autonaviAPI.GetCoordinateTownInfo(dongguanLng, dongguanLat)
|
||
if townName != "周市镇" || townCode != "320583102000" {
|
||
t.Fatalf("townName:%s, townCode:%s", townName, townCode)
|
||
}
|
||
}
|
||
|
||
func TestGetDistricts(t *testing.T) {
|
||
districtList, err := autonaviAPI.GetDistricts(4, "成都")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
if len(districtList) == 0 {
|
||
t.Fatal("should have ditrict")
|
||
}
|
||
t.Log(utils.Format4Output(districtList, false))
|
||
}
|
||
|
||
func TestGetCoordinateFromAddress(t *testing.T) {
|
||
lng, lat, districtCode := autonaviAPI.GetCoordinateFromAddress("广东广州市白云区棠景街道水边街棠下村东一街36号(可放北街的菜鸟驿站)", "广州")
|
||
t.Logf("lng:%f, lat:%f, districtCode:%d", lng, lat, districtCode)
|
||
}
|
||
|
||
func TestWalkingDistance(t *testing.T) {
|
||
distance := autonaviAPI.WalkingDistance(104.057289, 30.694798, 104.066289, 30.695598)
|
||
t.Logf("distance:%f", distance)
|
||
}
|
||
|
||
func TestGeoCodeRegeo(t *testing.T) {
|
||
lng := 104.052756
|
||
lat := 30.685203
|
||
result, err := autonaviAPI.GeoCodeRegeo([]*Coordinate{
|
||
&Coordinate{
|
||
Lng: lng,
|
||
Lat: lat,
|
||
},
|
||
&Coordinate{
|
||
Lng: lng,
|
||
Lat: lat,
|
||
},
|
||
}, 0, false, nil, 0, 0)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestBatchWalkingDistance(t *testing.T) {
|
||
result, err := autonaviAPI.BatchWalkingDistance(104.052756, 30.685203, []*Coordinate{
|
||
&Coordinate{
|
||
Lng: 104.052756,
|
||
Lat: 30.687203,
|
||
},
|
||
&Coordinate{
|
||
Lng: 104.032756,
|
||
Lat: 30.685203,
|
||
},
|
||
&Coordinate{
|
||
Lng: 104.032756,
|
||
Lat: 30.685203,
|
||
},
|
||
&Coordinate{
|
||
Lng: 104.032756,
|
||
Lat: 30.685203,
|
||
},
|
||
&Coordinate{
|
||
Lng: 104.032756,
|
||
Lat: 30.685203,
|
||
},
|
||
&Coordinate{
|
||
Lng: 104.032756,
|
||
Lat: 30.685203,
|
||
},
|
||
&Coordinate{
|
||
Lng: 104.032756,
|
||
Lat: 30.685203,
|
||
},
|
||
})
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
t.Log(utils.Format4Output(result, false))
|
||
}
|
||
|
||
func TestAA(t *testing.T) {
|
||
result, err := autonaviAPI.GetCoordinateAreaInfo(113.325814, 23.133907)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
t.Log(utils.Format4Output(result, false))
|
||
}
|