init
This commit is contained in:
30
internal/service/location_service.go
Normal file
30
internal/service/location_service.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"qd-sc/internal/client"
|
||||
"qd-sc/internal/config"
|
||||
)
|
||||
|
||||
// LocationService 地理位置服务
|
||||
type LocationService struct {
|
||||
cfg *config.Config
|
||||
amapClient *client.AmapClient
|
||||
}
|
||||
|
||||
// NewLocationService 创建位置服务
|
||||
func NewLocationService(cfg *config.Config, amapClient *client.AmapClient) *LocationService {
|
||||
return &LocationService{
|
||||
cfg: cfg,
|
||||
amapClient: amapClient,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryLocation 查询地点经纬度
|
||||
func (s *LocationService) QueryLocation(keywords string) (latitude, longitude string, err error) {
|
||||
lat, lng, err := s.amapClient.GetLocationCoordinates(keywords)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("查询地点失败: %w", err)
|
||||
}
|
||||
return lat, lng, nil
|
||||
}
|
||||
Reference in New Issue
Block a user