简体   繁体   English

将自定义文本添加到 Google Maps Static?

[英]Add custom text to Google Maps Static?

Is it possible to add a custom text to google static map?是否可以向谷歌静态地图添加自定义文本?

I am using google static as following:我使用谷歌静态如下:

https://maps.googleapis.com/maps/api/staticmap?&zoom=7&text=testcenter=51.45400691005982,-4.4439697265625&size=600x600&maptype=roadmap&key=key&path=xxx,yyy

Ok so here is the thing, Google Maps Static populates your DOM with an image essentially.好的,事情就是这样,Google Maps Static 本质上是用图像填充您的 DOM。 Though you can modify characteristics of this image, it comes from google and is not modifiable in your DOM - what you see is all that you get.尽管您可以修改此图像的特征,但它来自 google,并且无法在您的 DOM 中进行修改 - 您所看到的就是您得到的全部。 To overlay text you need to embed the map div inside another div in which you will place the text.要覆盖文本,您需要将地图 div 嵌入到另一个 div 中,您将在其中放置文本。

Basically it should look like this:基本上它应该是这样的:

<div class="wrapper">

    <div id="googleMap">
        <img src="https://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400">
   </div>

   <div id="mapText">
      <span>THIS IS YOUR TEXT</span>
   </div>

</div> 

Then you can use CSS to style exactly how and where you want this text to appear overlayed on the map.然后,您可以使用 CSS 精确设置您希望此文本在地图上叠加显示的方式和位置。

.wrapper {
  position: relative;
}

#mapText {
  position: absolute;
  bottom: 50%;
  font-family: sans-serif;
  font-size: 30px;
  color: red;
}

Tested this on fiddle and it works fine.在小提琴上对此进行了测试,效果很好。 Hope this helped!希望这有帮助!

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

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