diff --git a/platform/csv/pool.go b/platform/csv/pool.go index 49d0148b..ac422e13 100644 --- a/platform/csv/pool.go +++ b/platform/csv/pool.go @@ -139,14 +139,17 @@ func geocodePool(ctx context.Context, txn bob.Tx, client *stadia.StadiaMaps, job PostalCode: pool.AddressPostalCode, Street: pool.AddressStreet, } - address, err := geocode.GeocodeStructured(ctx, job.org, a) + geo, err := geocode.GeocodeStructured(ctx, job.org, a) if err != nil { addError(ctx, txn, job.csv, job.rownumber, 0, err.Error()) } - geom_query := geom.PostgisPointQuery(address.Location) + if geo.Address.Location == nil { + return fmt.Errorf("nil location") + } + geom_query := geom.PostgisPointQuery(*geo.Address.Location) _, err = psql.Update( um.Table("fileupload.pool"), - um.SetCol("h3cell").ToArg(address.Cell), + um.SetCol("h3cell").ToArg(geo.Cell), um.SetCol("geom").To(geom_query), um.Where(psql.Quote("id").EQ(psql.Arg(pool.ID))), ).Exec(ctx, txn) diff --git a/platform/geocode/by_gid.go b/platform/geocode/by_gid.go index c7ae32c9..071a7e31 100644 --- a/platform/geocode/by_gid.go +++ b/platform/geocode/by_gid.go @@ -40,6 +40,7 @@ func ByGID(ctx context.Context, gid string) (*GeocodeResult, error) { GID: feature.Properties.GID, ID: &id, Locality: feature.Properties.Context.WhosOnFirst.Locality.Name, + Location: &location, Number: feature.Properties.AddressComponents.Number, PostalCode: feature.Properties.AddressComponents.PostalCode, Raw: feature.Properties.FormattedAddressLine, @@ -47,7 +48,6 @@ func ByGID(ctx context.Context, gid string) (*GeocodeResult, error) { Street: feature.Properties.AddressComponents.Street, Unit: "", }, - Cell: cell, - Location: location, + Cell: cell, }, nil } diff --git a/platform/geocode/geocode.go b/platform/geocode/geocode.go index 66402bb0..dd500f8f 100644 --- a/platform/geocode/geocode.go +++ b/platform/geocode/geocode.go @@ -23,9 +23,8 @@ import ( ) type GeocodeResult struct { - Address types.Address - Cell h3.Cell - Location types.Location + Address types.Address + Cell h3.Cell } var client *stadia.StadiaMaps @@ -115,9 +114,13 @@ func toGeocodeResult(resp stadia.GeocodeResponse, address_msg string) (*GeocodeR // Depending on what kind of request we made we'll get wildly different result structures // This first structure generally works for forword geocoding address := types.Address{ - Country: country_s, - GID: feature.Properties.GID, - Locality: feature.Properties.Locality, + Country: country_s, + GID: feature.Properties.GID, + Locality: feature.Properties.Locality, + Location: &types.Location{ + Longitude: feature.Geometry.Coordinates[0], + Latitude: feature.Geometry.Coordinates[1], + }, Number: feature.Properties.HouseNumber, PostalCode: feature.Properties.PostalCode, Region: feature.Properties.Region, @@ -136,10 +139,6 @@ func toGeocodeResult(resp stadia.GeocodeResponse, address_msg string) (*GeocodeR return &GeocodeResult{ Address: address, Cell: cell, - Location: types.Location{ - Longitude: feature.Geometry.Coordinates[0], - Latitude: feature.Geometry.Coordinates[1], - }, }, nil } diff --git a/resource/geocode.go b/resource/geocode.go index 95af1fae..f15abfe4 100644 --- a/resource/geocode.go +++ b/resource/geocode.go @@ -16,16 +16,14 @@ type geocodeR struct { router *router } type geocode struct { - Address types.Address `json:"address"` - Cell h3.Cell `json:"cell"` - Location types.Location `json:"location"` + Address types.Address `json:"address"` + Cell h3.Cell `json:"cell"` } func newGeocode(g *ngeocode.GeocodeResult) *geocode { return &geocode{ - Address: g.Address, - Cell: g.Cell, - Location: g.Location, + Address: g.Address, + Cell: g.Cell, } } diff --git a/ts/rmo/components/AddressAndMapLocator.vue b/ts/rmo/components/AddressAndMapLocator.vue index e3fdef88..0b70ded5 100644 --- a/ts/rmo/components/AddressAndMapLocator.vue +++ b/ts/rmo/components/AddressAndMapLocator.vue @@ -123,7 +123,7 @@ async function doAddressSuggestionDetails(suggestion: GeocodeSuggestion) { console.log("suggestion located, zooming", data); currentCamera.value.zoom = 15; } - updateModel(data.address.gid, data.address.raw, data.location); + updateModel(data.address.gid, data.address.raw, data.address.location); } function doMapClick(location: Location) { updateModel(props.modelValue.gid, props.modelValue.raw, location); diff --git a/ts/type/api.ts b/ts/type/api.ts index 49518125..20ecdd52 100644 --- a/ts/type/api.ts +++ b/ts/type/api.ts @@ -86,7 +86,6 @@ export interface GeocodeSuggestion { export interface Geocode { address: Address; cell: number; - location: Location; } export interface LogEntryDTO { created: string;