baidu lbs
This commit is contained in:
parent
056927329e
commit
24ac136efc
|
@ -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
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package adapi
|
||||
package unify
|
||||
|
||||
import (
|
||||
"encoding/json"
|
|
@ -1,4 +1,4 @@
|
|||
package adapi
|
||||
package unify
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package adapi
|
||||
package unify
|
||||
|
||||
import (
|
||||
"errors"
|
|
@ -1,4 +1,4 @@
|
|||
package adminapi
|
||||
package unify
|
||||
|
||||
import (
|
||||
"encoding/json"
|
|
@ -1,4 +1,4 @@
|
|||
package adminapi
|
||||
package unify
|
||||
|
||||
import (
|
||||
"encoding/json"
|
|
@ -1,4 +1,4 @@
|
|||
package adminapi
|
||||
package unify
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package payapi
|
||||
package unify
|
||||
|
||||
import (
|
||||
"encoding/json"
|
|
@ -1,4 +1,4 @@
|
|||
package payapi
|
||||
package unify
|
||||
|
||||
import (
|
||||
"encoding/json"
|
|
@ -1,4 +1,4 @@
|
|||
package payapi
|
||||
package unify
|
||||
|
||||
type OrderUser struct {
|
||||
UserId string `json:"userId"`
|
Loading…
Reference in New Issue