fixing Geo

This commit is contained in:
Salim Amine Bou Aram
2024-11-01 01:03:07 +01:00
parent 8956914969
commit 41bcb74462
2 changed files with 20 additions and 13 deletions

View File

@@ -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
}