我以前见过这个问题,但没有看到有助于解决问题的答案。
这是地图嵌入代码:
<iframe style="border: 0;" src="https://www.google.com/maps/embed/v1/search?key=AIzaSyD500KZjSof98vSBhKTytpoP3rlJi69WXM=senior+assisted+care+near+me&zoom=9" width="600" height="450" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
我在Wordpress网站上嵌入了这个。
有人知道我为什么会犯这个错误吗?
错误:Google Maps Platform rejected your request. Invalid request. Missing the 'q' parameter
您收到错误:Google Maps Platform rejected your request. Invalid request. Missing the 'q' parameter
,因为您在URL:中没有q=
参数
<iframe style="border: 0;" src="https://www.google.com/maps/embed/v1/search?key=AIzaSyD500KZjSof98vSBhKTytpoP3rlJi69WXM=senior+assisted+care+near+me&zoom=9" width="600" height="450" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
应为:
<iframe style="border: 0;" src="https://www.google.com/maps/embed/v1/search?key=AIzaSyD500KZjSof98vSBhKTytpoP3rlJi69WXM&q=senior+assisted+care+near+me&zoom=9" width="600" height="450" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
(密钥后加&q
,=
符号前加(
工作代码片段(您可能需要限制密钥…(:
<iframe style="border: 0;" src="https://www.google.com/maps/embed/v1/search?key=AIzaSyD500KZjSof98vSBhKTytpoP3rlJi69WXM&q=senior+assisted+care+near+me&zoom=9" width="600" height="450" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
我刚刚学会了这一点,它完全适用于这种情况!此处的视频:https://www.youtube.com/watch?v=5klko9khrEs
简短回答
添加gem dotenv rails,添加到Gemfile后,做一个"捆绑包"。
在.env->写入:GMAPS_API_KEY=foo4398439837
现在在seeds.rb->写入:
byebug
ENV["GMAPS_API_KEY"]
现在在终端->写入:rails数据库:种子
如果键入:ENV["GMAPS_API_KEY"]
它将显示加密值(成功!(
在您的谷歌地图链接中<%=ENV["GMAPS_API_KEY"]%>应该有效!
前任。src=";https://www.google.com/maps/embed/v1/place?key=<%=ENV["GMAPS_API_KEY"]%>amp;q=NewYork";
我更进一步,使用地址的数据库值
前任。src=";https://www.google.com/maps/embed/v1/place?key=<%=ENV["GMAPS_API_KEY"]%>amp;q=<%=@property.address.to_param%>