fixing Geo
This commit is contained in:
parent
8956914969
commit
41bcb74462
|
@ -3,9 +3,9 @@ package handler
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
routing "git.coopgo.io/coopgo-platform/routing-service"
|
||||
"github.com/paulmach/orb"
|
||||
"github.com/paulmach/orb/geojson"
|
||||
"google.golang.org/genproto/googleapis/maps/routing/v2"
|
||||
)
|
||||
|
||||
func (h *SilverMobiHandler) GeoAutocomplete(text string) (*geojson.FeatureCollection, error) {
|
||||
|
@ -23,7 +23,9 @@ func (h *SilverMobiHandler) GeoRoute(locations geojson.FeatureCollection) (route
|
|||
)
|
||||
|
||||
for _, f := range locations.Features {
|
||||
|
||||
ft := f.Geometry.GeoJSONType()
|
||||
|
||||
if ft != featuresType {
|
||||
return nil, fmt.Errorf("mixing different types of geometries in"+
|
||||
" the feature collection is not allowed : %s and %s found", featuresType, ft)
|
||||
|
@ -34,11 +36,15 @@ func (h *SilverMobiHandler) GeoRoute(locations geojson.FeatureCollection) (route
|
|||
if featuresType == "Point" {
|
||||
if point, ok := f.Geometry.(orb.Point); ok {
|
||||
routeLocations = append(routeLocations, point)
|
||||
} else {
|
||||
return nil, fmt.Errorf("invalid geometry type for point")
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("feature type %s not supported", featuresType)
|
||||
}
|
||||
}
|
||||
|
||||
if route, err = h.Services.Routing.Route(routeLocations); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
|
||||
grpcproto "git.coopgo.io/coopgo-apps/silvermobi/servers/grpcapi/proto"
|
||||
"git.coopgo.io/coopgo-platform/routing-service"
|
||||
"github.com/google/uuid"
|
||||
"github.com/paulmach/orb/geojson"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
@ -52,6 +53,8 @@ func (s SilvermobiGRPCService) GeoRoute(ctx context.Context,
|
|||
req *grpcproto.GeoRouteRequest) (*grpcproto.GeoRouteResponse, error) {
|
||||
locationsRaw, ok := req.Locations.(*grpcproto.GeoRouteRequest_LocationsRaw)
|
||||
|
||||
var route *routing.Route
|
||||
|
||||
if !ok {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "could not read departure")
|
||||
}
|
||||
|
@ -61,20 +64,22 @@ func (s SilvermobiGRPCService) GeoRoute(ctx context.Context,
|
|||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
if _, err = s.Handler.GeoRoute(*locations); err != nil {
|
||||
if route, err = s.Handler.GeoRoute(*locations); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
route, _ := s.Handler.GeoRoute(*locations)
|
||||
|
||||
return &grpcproto.GeoRouteResponse{
|
||||
Polyline: route.Polyline.String(),
|
||||
Polyline: route.Summary.Polyline,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s SilvermobiGRPCService) GeoRouteWithReturn(ctx context.Context,
|
||||
req *grpcproto.GeoRouteWithReturnRequest) (*grpcproto.GeoRouteWithReturnResponse, error) {
|
||||
|
||||
var (
|
||||
route, returnRoute *routing.Route
|
||||
)
|
||||
|
||||
locationsRaw, ok := req.Locations.(*grpcproto.GeoRouteWithReturnRequest_LocationsRaw)
|
||||
|
||||
if !ok {
|
||||
|
@ -86,20 +91,16 @@ func (s SilvermobiGRPCService) GeoRouteWithReturn(ctx context.Context,
|
|||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
if _, err = s.Handler.GeoRoute(*locations); err != nil {
|
||||
if route, err = s.Handler.GeoRoute(*locations); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
route, _ := s.Handler.GeoRoute(*locations)
|
||||
|
||||
if _, err = s.Handler.GeoReturnRoute(*locations); err != nil {
|
||||
if returnRoute, err = s.Handler.GeoReturnRoute(*locations); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
returnRoute, _ := s.Handler.GeoReturnRoute(*locations)
|
||||
|
||||
return &grpcproto.GeoRouteWithReturnResponse{
|
||||
Polyline: route.Polyline.String(),
|
||||
ReturnPolyline: returnRoute.Polyline.String(),
|
||||
Polyline: route.Summary.Polyline,
|
||||
ReturnPolyline: returnRoute.Summary.Polyline,
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue