Google 地图显示不带气泡的地标名称

Google Maps display names of placemarks without the bubbles

我正在尝试将 kml 文件叠加到 Android 的 google 地图中的地面叠加图像上。多边形显示正确但地标的名称未显示,取而代之的是气泡,单击时仅显示名称。

这是 android 地图显示的图像,而不是在 google earth screenshot of kml overlay

上正确呈现的名称

这是 kml 文件的示例

    <?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
    <Document>
        <open>1</open>
        <Style id="Style_5">
        <IconStyle><scale>0</scale></IconStyle>
        <LabelStyle><color>9900ffff</color><scale>1</scale></LabelStyle><LineStyle><color>990000ff</color><width>1.5</width></LineStyle><PolyStyle><color>997f7fff</color><fill>0</fill><outline>1</outline></PolyStyle>
        </Style>
                <Placemark id="pm1">
                    <name>
                        <![CDATA[Name of place]]>
                    </name>
                    <Snippet maxLines="0">empty</Snippet>
                    <styleUrl>#Style_5</styleUrl>
                    <MultiGeometry>
                        <Point id="g0">
                            <altitudeMode>clampToGround</altitudeMode>
                            <coordinates>37.3870283588389,3.89010909235333</coordinates>
                        </Point>
                        <MultiGeometry>
                            <Polygon id="g1">
                                <altitudeMode>clampToGround</altitudeMode>
                                <outerBoundaryIs>
                                    <LinearRing>
<coordinates>37.488080789205128,4.004061832979036 37.493240913308938,3.932680116209725 37.490660851257033,3.907739516374665 37.486360747837196,3.893979185431183 37.478620561681488,3.884518957907539 37.281675825052908,3.776156351727622 37.284255887104806,3.783036517199363 37.288555990524642,3.789056661987136 37.290276031892581,3.799376910194747 37.300596280100194,3.80539705498252 37.298876238732255,3.815717303190131 37.303176342152092,3.826037551397743 37.304036362836065,3.839797882341224 37.311776548991773,3.852698192600738 37.3109165283078,3.865598502860252 37.309196486939868,3.878498813119766 37.309196486939868,3.902579392270859 37.316936673095576,3.933540136893693 37.323816838567318,3.950740550573045 37.321236776515413,3.967940964252397 37.280815804368935,3.989441481351587 37.294576135312418,4.002341791611101 37.488080789205128,4.004061832979036</coordinates>
                                    </LinearRing>
                                </outerBoundaryIs>
                            </Polygon>
                        </MultiGeometry>
                    </MultiGeometry>
                </Placemark>
    </Document>
</kml>

地图 API 不支持地球支持的所有 KML 元素,我相信您想要的图标和标签选项属于不受支持的元素。如果我理解正确,您希望 KML 文件在地图上显示时不带图标(您已将 IconStyle/scale 设置为零),而是只显示每个点的标签(您设置了 LabelStyle)。

查看 KML in the Maps Javascript API, you can see that <scale> is not supported so you can't make the icons zero size, and <LabelStyle> is not supported at all. But I just realized that there is separate documentation for the Maps Android SDK 的文档,其中说支持 <scale>,因此您应该可以调整图标大小...但不支持 <LabelStyle> ,这可能意味着不支持标签。请注意,<IconStyle> 似乎在两者中都受支持,但 Android SDK 支持其子标签 <color>,但 Javascript API 不支持。

您应该能够测试 IconStyle > scale 标签,方法是尝试使用仅包含简单点和几个图标缩放选项的 KML 文件,看看哪个有效(零可能是一种特殊情况?)。您也可以尝试一个没有样式的简单标签,看看您是否能让标签正常工作,但我怀疑它们不会。

android 地图实用程序库的新版本部分解决了这个问题,android-maps-utils

但目前,它不允许像上面的 Kml 中的 0 比例。一个可行的解决方案是编写一个 kml 解析器以从 kml 文件中提取数据,然后覆盖在地图上。 Here is an example 将数据解析为 java 个对象。