hpds_jkw_web/pkg/minedata/minedata.go

96 lines
2.4 KiB
Go
Raw Normal View History

2023-01-11 18:05:29 +08:00
package minedata
import (
"encoding/json"
"fmt"
)
type MineDateClient struct {
AppKey string
}
func NewMineData(key string) *MineDateClient {
return &MineDateClient{
AppKey: key, //默认 f0bda738033e47ffbfbd5d3f865c19e1
}
}
// ReverseGeocoding 逆地理
func (client *MineDateClient) ReverseGeocoding(lng, lat float64) (data *ReverseGeocodingResponse, err error) {
params := make(map[string]string)
params["location"] = fmt.Sprintf("%.6f, %.6f", lng, lat)
params["type"] = "道路"
params["coordtype"] = "02"
params["radius"] = "100"
params["extensions"] = "road"
params["key"] = client.AppKey
res, err := HttpDo(ReverseGeocodingUrl, "GET", params, make(map[string]string))
if err != nil {
return nil, err
}
data = new(ReverseGeocodingResponse)
err = json.Unmarshal(res, data)
if err != nil {
return nil, err
}
return data, err
}
// MilepostService 正里程桩服务
func (client *MineDateClient) MilepostService(formatName string) (data *MilepostResponse, err error) {
params := make(map[string]string)
params["key"] = client.AppKey
params["format_name"] = formatName
res, err := HttpDo(MilepostUrl, "GET", params, make(map[string]string))
if err != nil {
return nil, err
}
data = new(MilepostResponse)
fmt.Println(string(res))
err = json.Unmarshal(res, data)
if err != nil {
return nil, err
}
return data, err
}
// ReverseMilepost 逆里程桩
func (client *MineDateClient) ReverseMilepost(lng, lat float64) (data *ReverseMilepostResponse, err error) {
params := make(map[string]string)
params["key"] = client.AppKey
params["location"] = fmt.Sprintf("%.6f, %.6f", lng, lat)
res, err := HttpDo(ReverseMilepostUrl, "GET", params, make(map[string]string))
if err != nil {
return nil, err
}
data = new(ReverseMilepostResponse)
fmt.Println(string(res))
err = json.Unmarshal(res, data)
if err != nil {
return nil, err
}
return data, err
}
// RoadSearch 道路搜索
func (client *MineDateClient) RoadSearch(keywords string) (data *RoadSearchResponse, err error) {
params := make(map[string]string)
params["key"] = client.AppKey
params["keywords"] = keywords
params["city"] = "330000"
params["page_idx"] = "1"
params["page_size"] = "20"
params["extensions"] = "all"
params["citylimit"] = "true"
res, err := HttpDo(RoadSearchUrl, "GET", params, make(map[string]string))
if err != nil {
return nil, err
}
data = new(RoadSearchResponse)
err = json.Unmarshal(res, data)
if err != nil {
return nil, err
}
return data, err
}