Canapin
(Coin-coin le Canapin)
2. November 2022 um 11:57
1
I’m facing a weird behavior with Google Maps link.
Sometimes, they properly embed, and sometimes the onebox request returns a 404. I couldn’t find a way to reproduce the issue consistently, but it’s very often. Just try to paste links, move the google maps camera or cropping, try again, etc…
I first thought about a rate limit, but it’s not. The links that work and those that don’t are the same here or on my forum . Example:
Does anyone have an idea about where this issue comes from? Google side? Discourse side? Should it be moved to bug ?
5 „Gefällt mir“
This is kind of weird, I just happened to notice the pattern… but I think it has something to do with the zoom level in the link?
15.5z
15z
16.75z
17z
An entirely different location…
15.38z
15z
My guess is that it’s a Google Maps onebox engine issue on our end?
8 „Gefällt mir“
Falco
(Falco)
21. Februar 2023 um 22:02
4
Nice sleuthing @awesomerobot !
Looks like our regex for zoom level doesn’t allow dots here:
break if type != :standard
sleep 0.1
end
end
case type
when :standard
# Fallback for map URLs that don't resolve into an easily embeddable old-style URI
# Roadmaps use a "z" zoomlevel, satellite maps use "m" the horizontal width in meters
# TODO: tilted satellite maps using "a,y,t"
match = @url.match(/@(?<lon>[\d.-]+),(?<lat>[\d.-]+),(?<zoom>\d+)(?<mz>[mz])/)
raise "unexpected standard url #{@url}" unless match
zoom = match[:mz] == "z" ? match[:zoom] : Math.log2(57280048.0 / match[:zoom].to_f).round
location = "#{match[:lon]},#{match[:lat]}"
url = "https://maps.google.com/maps?ll=#{location}&z=#{zoom}&output=embed&dg=ntvb"
url += "&q=#{$1}" if match = @url.match(%r{/place/([^/\?]+)})
url += "&cid=#{($1 + $2).to_i(16)}" if @url.match(/!3m1!1s0x(\h{16}):0x(\h{16})/)
@url = url
@placeholder =
"https://maps.googleapis.com/maps/api/staticmap?maptype=roadmap¢er=#{location}&zoom=#{zoom}&size=690x400&sensor=false"
when :custom
Quite an easy fix.
9 „Gefällt mir“
Canapin
(Coin-coin le Canapin)
22. Februar 2023 um 00:01
5
What a catch
Thanks for figuring it out!
2 „Gefällt mir“
zogstrip
(Régis Hanol)
28. Februar 2023 um 21:36
7
@loic can you have a quick look at this one?
1 „Gefällt mir“
zogstrip
(Régis Hanol)
2. März 2023 um 09:39
11
Rebuilding @awesomerobot ’s post and all the Google Maps links are now working
Closing this.
6 „Gefällt mir“