70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package coryCommon
|
|
|
|
import (
|
|
"github.com/gogf/gf/v2/net/gclient"
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
)
|
|
|
|
// 高德地图API https://lbs.amap.com/api/webservice/guide/api/georegeo
|
|
|
|
// InverseGeocoding 逆地理编码
|
|
func InverseGeocoding(location string) (we string) {
|
|
//请求路径
|
|
key := "3bbede95174c607a1ed4c479d3f637cc"
|
|
requestURL := "https://restapi.amap.com/v3/geocode/regeo?location=" + location + "&key=" + key
|
|
|
|
response, err := gclient.New().ContentJson().ContentType("application/x-www-form-urlencoded").Get(gctx.New(), requestURL)
|
|
if err != nil {
|
|
return
|
|
}
|
|
var dataInfo = ""
|
|
dataInfo = response.ReadAllString()
|
|
return dataInfo
|
|
}
|
|
|
|
type InverseGeocodingRep struct {
|
|
Status string `json:"status"`
|
|
Regeocode Regeocode `json:"regeocode"`
|
|
Info string `json:"info"`
|
|
Infocode string `json:"infocode"`
|
|
}
|
|
|
|
type Regeocode struct {
|
|
FormattedAddress string `json:"formatted_address"`
|
|
AddressComponent AddressComponent `json:"addressComponent"`
|
|
}
|
|
|
|
type AddressComponent struct {
|
|
//City string `json:"city"`
|
|
Province string `json:"province"`
|
|
Adcode string `json:"adcode"`
|
|
District string `json:"district"`
|
|
Towncode string `json:"towncode"`
|
|
//StreetNumber StreetNumber `json:"streetNumber"`
|
|
Country string `json:"country"`
|
|
Township string `json:"township"`
|
|
//BusinessAreas []One `json:"businessAreas"`
|
|
//Building Two `json:"building"`
|
|
//Neighborhood Two `json:"neighborhood"`
|
|
Citycode string `json:"citycode"`
|
|
}
|
|
|
|
type StreetNumber struct {
|
|
Number string `json:"number"`
|
|
Location string `json:"location"`
|
|
Direction string `json:"direction"`
|
|
Distance string `json:"distance"`
|
|
Street string `json:"street"`
|
|
}
|
|
|
|
type One struct {
|
|
Location string `json:"location"`
|
|
Name string `json:"name"`
|
|
Id string `json:"id"`
|
|
}
|
|
|
|
type Two struct {
|
|
Name []string `json:"name"`
|
|
Type []string `json:"type"`
|
|
}
|