Canapin
(Coin-coin le Canapin)
November 2, 2022, 11:57am
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 Likes
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 Likes
Falco
(Falco)
February 21, 2023, 10:02pm
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 Likes
Canapin
(Coin-coin le Canapin)
February 22, 2023, 12:01am
5
What a catch
Thanks for figuring it out!
2 Likes
zogstrip
(Régis Hanol)
February 28, 2023, 9:36pm
7
@flink91 can you have a quick look at this one?
1 Like
zogstrip
(Régis Hanol)
March 2, 2023, 9:39am
11
Rebuilding @awesomerobot ’s post and all the Google Maps links are now working
Closing this.
6 Likes