Skip to content

Commit 64f2bad

Browse files
committed
Add street_view_url field to extract Street View panorama links
Extract panoid from Street View thumbnail URLs in category images and construct a direct Google Maps Street View URL that opens the panorama view of the location. URL format: https://www.google.com/maps/@?api=1&map_action=pano&pano={panoid}
1 parent 95a1cc2 commit 64f2bad

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

gmaps/entry.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import (
66
"iter"
77
"math"
88
"net/url"
9+
"regexp"
910
"runtime/debug"
1011
"slices"
1112
"strconv"
1213
"strings"
1314
)
1415

16+
var panoidRegex = regexp.MustCompile(`panoid=([^&]+)`)
17+
1518
type Image struct {
1619
Title string `json:"title"`
1720
Image string `json:"image"`
@@ -84,6 +87,7 @@ type Entry struct {
8487
Timezone string `json:"timezone"`
8588
PriceRange string `json:"price_range"`
8689
DataID string `json:"data_id"`
90+
StreetViewURL string `json:"street_view_url"`
8791
Images []Image `json:"images"`
8892
Reservations []LinkSource `json:"reservations"`
8993
OrderOnline []LinkSource `json:"order_online"`
@@ -180,6 +184,7 @@ func (e *Entry) CsvHeaders() []string {
180184
"timezone",
181185
"price_range",
182186
"data_id",
187+
"street_view_url",
183188
"images",
184189
"reservations",
185190
"order_online",
@@ -218,6 +223,7 @@ func (e *Entry) CsvRow() []string {
218223
e.Timezone,
219224
e.PriceRange,
220225
e.DataID,
226+
e.StreetViewURL,
221227
stringify(e.Images),
222228
stringify(e.Reservations),
223229
stringify(e.OrderOnline),
@@ -357,6 +363,9 @@ func EntryFromJSON(raw []byte, reviewCountOnly ...bool) (entry Entry, err error)
357363
}
358364
}
359365

366+
// Extract Street View URL from images
367+
entry.StreetViewURL = extractStreetViewURL(entry.Images)
368+
360369
entry.Reservations = getLinkSource(getLinkSourceParams{
361370
arr: getNthElementAndCast[[]any](darray, 46),
362371
link: []int{0},
@@ -745,6 +754,20 @@ func stringify(v any) string {
745754
}
746755
}
747756

757+
// extractStreetViewURL finds the Street View image and extracts the panoid to create a proper URL
758+
func extractStreetViewURL(images []Image) string {
759+
for _, img := range images {
760+
if strings.Contains(img.Title, "Street View") {
761+
matches := panoidRegex.FindStringSubmatch(img.Image)
762+
if len(matches) > 1 {
763+
return fmt.Sprintf("https://www.google.com/maps/@?api=1&map_action=pano&pano=%s", matches[1])
764+
}
765+
}
766+
}
767+
768+
return ""
769+
}
770+
748771
func decodeURL(url string) (string, error) {
749772
quoted := `"` + strings.ReplaceAll(url, `"`, `\"`) + `"`
750773

0 commit comments

Comments
 (0)