baidu lbs

This commit is contained in:
jiangyong27 2024-06-28 22:07:15 +08:00
parent 056927329e
commit 24ac136efc
10 changed files with 50 additions and 9 deletions

41
baidu/lbs.go Normal file
View File

@ -0,0 +1,41 @@
package baidu
import (
"encoding/json"
"errors"
"fmt"
"github.com/smbrave/goutil"
)
type addressRsp struct {
Status int `json:"status"`
Result struct {
FormattedAddress string `json:"formatted_address"`
} `json:"result"`
}
type Lbs struct {
ak string
}
func NewLbs(ak string) *Lbs {
return &Lbs{
ak: ak,
}
}
func (l *Lbs) GetAddress(lng, lat float64) (string, error) {
reqUrl := fmt.Sprintf("https://api.map.baidu.com/reverse_geocoding/v3/?ak=s&output=json&coordtype=wgs84&location=%f,%f", l.ak, lat, lng)
rspBody, err := goutil.HttpGet(reqUrl, nil)
if err != nil {
return "", err
}
var rsp addressRsp
if err := json.Unmarshal(rspBody, &rsp); err != nil {
return "", err
}
if rsp.Status != 0 {
return "", errors.New(string(rspBody))
}
return rsp.Result.FormattedAddress, nil
}

View File

@ -1,4 +1,4 @@
package adapi package unify
import ( import (
"encoding/json" "encoding/json"

View File

@ -1,4 +1,4 @@
package adapi package unify
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package adapi package unify
import ( import (
"errors" "errors"

View File

@ -1,4 +1,4 @@
package adminapi package unify
import ( import (
"encoding/json" "encoding/json"

View File

@ -1,4 +1,4 @@
package adminapi package unify
import ( import (
"encoding/json" "encoding/json"

View File

@ -1,4 +1,4 @@
package adminapi package unify
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package payapi package unify
import ( import (
"encoding/json" "encoding/json"

View File

@ -1,4 +1,4 @@
package payapi package unify
import ( import (
"encoding/json" "encoding/json"

View File

@ -1,4 +1,4 @@
package payapi package unify
type OrderUser struct { type OrderUser struct {
UserId string `json:"userId"` UserId string `json:"userId"`