Created
January 12, 2026 08:14
-
-
Save ensean/90387bddf2a98e6b287d8a8d59a70a5a to your computer and use it in GitHub Desktop.
geplaces demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module aws-location-suggest | |
| go 1.23 | |
| require ( | |
| github.com/aws/aws-sdk-go-v2 v1.41.1 | |
| github.com/aws/aws-sdk-go-v2/config v1.32.7 | |
| github.com/aws/aws-sdk-go-v2/service/geoplaces v1.8.0 | |
| ) | |
| require ( | |
| github.com/aws/aws-sdk-go-v2/credentials v1.19.7 // indirect | |
| github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.17 // indirect | |
| github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.17 // indirect | |
| github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.17 // indirect | |
| github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect | |
| github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4 // indirect | |
| github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.17 // indirect | |
| github.com/aws/aws-sdk-go-v2/service/signin v1.0.5 // indirect | |
| github.com/aws/aws-sdk-go-v2/service/sso v1.30.9 // indirect | |
| github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.13 // indirect | |
| github.com/aws/aws-sdk-go-v2/service/sts v1.41.6 // indirect | |
| github.com/aws/smithy-go v1.24.0 // indirect | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "context" | |
| "fmt" | |
| "log" | |
| "github.com/aws/aws-sdk-go-v2/aws" | |
| "github.com/aws/aws-sdk-go-v2/config" | |
| "github.com/aws/aws-sdk-go-v2/service/geoplaces" | |
| "github.com/aws/aws-sdk-go-v2/service/geoplaces/types" | |
| ) | |
| const ( | |
| region = "us-east-1" | |
| ) | |
| func main() { | |
| ctx := context.Background() | |
| // Load AWS configuration with test profile | |
| cfg, err := config.LoadDefaultConfig(ctx, | |
| config.WithSharedConfigProfile("test"), | |
| config.WithRegion(region), | |
| ) | |
| if err != nil { | |
| log.Fatalf("Failed to load AWS config: %v", err) | |
| } | |
| // Create GeoPlaces client | |
| client := geoplaces.NewFromConfig(cfg) | |
| // Create suggest request | |
| maxResults := int32(10) | |
| input := &geoplaces.SuggestInput{ | |
| QueryText: aws.String("coffee shop"), | |
| MaxResults: aws.Int32(maxResults), | |
| BiasPosition: []float64{-123.1207, 49.2827}, // Vancouver coordinates [lng, lat] | |
| Language: aws.String("en"), | |
| // Optional: Add additional features | |
| AdditionalFeatures: []types.SuggestAdditionalFeature{ | |
| types.SuggestAdditionalFeatureTimeZone, | |
| types.SuggestAdditionalFeaturePhonemes, | |
| }, | |
| } | |
| // Call the Suggest API | |
| output, err := client.Suggest(ctx, input) | |
| if err != nil { | |
| log.Fatalf("Failed to call Suggest API: %v", err) | |
| } | |
| // Print results | |
| fmt.Printf("Found %d results:\n\n", len(output.ResultItems)) | |
| for i, item := range output.ResultItems { | |
| fmt.Printf("%d. %s (Type: %s)\n", i+1, aws.ToString(item.Title), item.SuggestResultItemType) | |
| if item.Place != nil { | |
| place := item.Place | |
| if place.Address != nil && place.Address.Label != nil { | |
| fmt.Printf(" Address: %s\n", aws.ToString(place.Address.Label)) | |
| } | |
| if len(place.Position) == 2 { | |
| fmt.Printf(" Position: [%.6f, %.6f]\n", place.Position[0], place.Position[1]) | |
| } | |
| if place.PlaceId != nil { | |
| fmt.Printf(" Place ID: %s\n", aws.ToString(place.PlaceId)) | |
| } | |
| if len(place.Categories) > 0 { | |
| fmt.Printf(" Categories: ") | |
| for j, cat := range place.Categories { | |
| if j > 0 { | |
| fmt.Printf(", ") | |
| } | |
| fmt.Printf("%s", aws.ToString(cat.Name)) | |
| } | |
| fmt.Println() | |
| } | |
| if place.TimeZone != nil { | |
| fmt.Printf(" TimeZone: %s (Offset: %s)\n", | |
| aws.ToString(place.TimeZone.Name), | |
| aws.ToString(place.TimeZone.Offset)) | |
| } | |
| } | |
| if item.Query != nil { | |
| fmt.Printf(" Query Type: %s\n", item.Query.QueryType) | |
| } | |
| fmt.Println() | |
| } | |
| // Print query refinements if any | |
| if len(output.QueryRefinements) > 0 { | |
| fmt.Println("Query Refinements:") | |
| for _, refinement := range output.QueryRefinements { | |
| fmt.Printf(" %s -> %s\n", | |
| aws.ToString(refinement.OriginalTerm), | |
| aws.ToString(refinement.RefinedTerm)) | |
| } | |
| } | |
| // Print pricing bucket if available | |
| if output.PricingBucket != nil { | |
| fmt.Printf("\nPricing Bucket: %s\n", aws.ToString(output.PricingBucket)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment