【问题标题】:KML Placemark Icon has different anchor point in Google Earth than when loaded in Google Maps, Why?KML 地标图标在 Google 地球中的锚点与在 Google 地图中加载时的锚点不同,为什么?
【发布时间】:2021-12-15 12:10:49
【问题描述】:

我有一个 KML 文件,其中包含带有自定义图标的地标。

在 Google 地球中查看时,锚点位于图标的中心。像这样……

在我网站上的 Google 地图中查看 KML 文件时,锚点变为图标的底部中心。像这样……

这是为什么?以及如何更改它,以便在由 Google Maps API 加载时,锚点位于图标的中心?

这是 KML 文件中的样式...

<Style id="Parking">
    <IconStyle><Icon><href>http://www.virtualmountains.co.uk/shared/Parking.png</href></Icon></IconStyle>
    <BalloonStyle>
        <text>$[description]</text>
        <bgColor>white</bgColor>
        <text><![CDATA[
            <font color="#674A32" face="arial" align="justify">$[description]</font>
        ]]></text>
    </BalloonStyle>
    <LabelStyle>
        <color>FFFFFFFF</color>
        <scale>0.8</scale>
    </LabelStyle>
</Style>

这是地标代码...

<Placemark>
    <name>A5 Parking, Tryfan</name>
     <description>        
        <![CDATA[
            <DIV style="max-width:400px; margin-right:10px; margin-bottom:10px; color:#674A32; font-family:Arial">
                <DIV style="font-size:11pt; font-weight:bold; text-align:left">A5 Parking, Tryfan<BR></DIV>
                <DIV style="font-size:10pt; text-align:justify"><BR>
                    There is a parking here alongside a great length of the A5.
                </DIV>
            </DIV>
        ]]>
    </description>
    <styleUrl>#Parking</styleUrl>  
    <Point><coordinates> -3.991196, 53.125136,0</coordinates></Point>
</Placemark>

【问题讨论】:

标签: google-maps-api-3 kml google-earth


【解决方案1】:

您可以将 KML 中地标图标的锚点或“热点”指定为 &lt;IconStyle&gt; 的一部分。 &lt;hotspot&gt; 标签允许您在 x(左/右)和 y(上/下)方向上使用分数(0 到 1)或像素尺寸指定图标上的锚点。

例如,如果你想让你的图标锚定在每个图标的中心,你可以让你的 IconStyle 看起来像这样:

<IconStyle>
  <Icon>
    <href>http://www.virtualmountains.co.uk/shared/Parking.png</href>
  </Icon>
  <hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction">
</IconStyle>

这应该适用于 Google 地球和 Google 地图中的 KML。

您可以在 KML 参考中找到&lt;hotspot&gt; 标记的文档,此处为:https://developers.google.com/kml/documentation/kmlreference#hotspot

【讨论】:

  • 应该适用于谷歌地图,但不适用。见issuetracker.google.com/issues/35830017
  • 感谢 Christiaan,这是我丢失的代码,但正如 geocodezip 所说,由于某种原因无法正常工作,尽管我确实尝试过以防万一它已被修复。
猜你喜欢
  • 1970-01-01
  • 2012-05-22
  • 1970-01-01
  • 1970-01-01
  • 2015-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-05
相关资源
最近更新 更多