简体   繁体   English

嵌入式Google地图未以特定网络上的位置为中心

[英]Embeded google map not centering on location on specific networks

I'm using embed google maps for rendering map with dynamic location on specific page with specific location. 我正在使用嵌入的Google地图在具有特定位置的特定页面上呈现具有动态位置的地图。 Iframe contains url to google embed map with q= parameter to retrieve location. iframe包含带有q=参数的Google嵌入地图的网址,以检索位置。 For example like this: 例如这样:

<iframe height="200" frameborder="0" style="border:0; width:100%;" src="https://www.google.com/maps/embed/v1/place?key=GOOGLE_API_KEY_HERE&q=Fabryczna+20A,+Kraków,+Poland" allowfullscreen></iframe>

Usually it renders just fine, like here: 通常它可以很好地渲染,就像这里: 正确渲染嵌入Google地图的方法

But what is weird, sometimes on same browser, same hardware it renders like there would be no address provided: 但是奇怪的是,有时在相同的浏览器上,它呈现的相同硬件就像没有提供地址一样:

嵌入Google地图的渲染方式错误

What I've observed - it seems to be related to different networks (but not network speed) - so for example I was able to view map just fine using my home wifi, but when I switched to my office network, or mobile (for example using personal hotspot and cellular network) issue would occur. 我观察到的内容-似乎与不同的网络有关(但与网络速度无关)-例如,我可以使用家庭wifi很好地查看地图,但是当我切换到办公室网络或移动设备(用于使用个人热点和蜂窝网络的示例)问题。

When this issue occurs iframe src is the same as when it's not present. 发生此问题时,iframe src与不存在时相同。 But the content of an iframe changes. 但是iframe的内容会发生变化。

How to deal with this issue? 该如何处理?

Thanks 谢谢

There is a fairly simple solution for this. 有一个相当简单的解决方案。 It has to do with the Google API key. 它与Google API密钥有关。 If you would like to embed your location on your website I recommend using the embed function Google Maps has to offer. 如果您想在您的网站上嵌入自己的位置,我建议您使用Google Maps提供的嵌入功能。

Simple do as followed: 简单做如下:

Type in your location in Google Maps > Share > Embed Map. 在Google地图>共享>嵌入地图中输入您的位置。

You will end up with a code like this: 您将得到如下代码:

<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2488.201651849343!2d19.975045070729283!3d50.06547331892074!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x47165b28caac7d19%3A0xbd9f87d30b21ac38!2sFabryczna+20A%2C+Krak%C3%B3w%2C+Poland!5e0!3m2!1sen!2snl!4v1510144269138" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>

You can also determine what you will see in your embedded Google Maps by scrolling before you embed the map. 您还可以在嵌入地图之前通过滚动来确定将在嵌入式Google地图中看到的内容。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM