百分比编码的网址已被Google Earth破坏 [英] percent-encoded URLs are mangled by Google Earth
问题描述
在用于Google Earth消耗的KML文件中,我使用的是Google Charts动态图标,其URL包含百分比编码字符,例如
In a KML file for Google Earth consumption I am using Google Charts dynamic icons whose URLs contain percent-encode characters, e.g., this one. As can be seen by intercepting network calls, the %E2%80%A2 (bullet character) is mangled by Google Earth into %C3%A2%C2%80%C2%A2, which causes the icon retrieval to fail. The problem is that the KML spec is extremely vague: of the IconStyle Icon href element it will only say that it is "an HTTP address [...] used to load an icon". So, can any Googler clarify what Google Earth expects and how to make icon URLs in KML files with percent-encoded characters work properly?
请不要让我为上面的URL可能是某种不正确而感到悲伤:它在浏览器中可以正常工作(用与号替换
后),并且有一个示例正好在动态图标开发人员参考.
Please do not give me grief about how maybe the URL above is somehow incorrect: it works fine in a browser (after replacing 
with the ampersand) and there is an example just like it about halfway through the dynamic icons developer reference.
实际的KML示例文件如下:
An actual KML example file follows:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Folder>
<Placemark>
<Style>
<IconStyle>
<scale>1.6</scale>
<Icon>
<!-- doesn't work -->
<href>http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&chld=%E2%80%A2|cccccc|000000</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>-3.67,40.51</coordinates>
</Point>
</Placemark>
<Placemark>
<Style>
<IconStyle>
<scale>1.6</scale>
<Icon>
<!-- works -->
<href>http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&chld=O|cccccc|000000</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>-3.68,40.52</coordinates>
</Point>
</Placemark>
</Folder>
</Document>
</kml>
推荐答案
经过长时间的沉寂,我回到了这个话题,并找到了答案.即使您要插入URL,因此URL编码准则也应适用.KML希望特殊实体即使在URL中也要采用Unicode编码,而不是URL编码!换句话说,您需要这样做:
I came back to this after a long lull and found the answer. Even though you are inserting an URL and thus URL encoding guidelines should apply KML expects special entities to be Unicode- and not URL-encoded even in URLs! In other words you need this:
<href>http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&chld=•|cccccc|000000</href>
回顾一下它要求"的事实.因为&符应该让我走上正确的路,但是事后看来总是20/20 ...
In retrospect the fact that that it requires "" for the ampersand should have put me on the right track but hindsight is always 20/20...
这篇关于百分比编码的网址已被Google Earth破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!