0

我即时生成 KML 文件。生成后,我像这样调用 Google 地图:

http://maps.google.com/maps?q=http://<my ip>:8081/<location>/<name>.kml. 我使用的文件名基于用户输入的起始位置的纬度/经度。显然,当位置相同时,会从相同位置开始生成一个新的 kml 文件。在这种情况下,应该覆盖旧的,就是这样。但是,当它提供给谷歌地图时,谷歌地图会显示旧文件。我附上了来自两个示例文件和 python 代码的片段来说明这种情况:

import sys
import simplekml
kml=simplekml.Kml()
data=open(sys.argv[1],'r')
for line in data:
    points=line.split(' ')
    #speed=float(points[9])*3.6
    poly=kml.newpolygon(description=("Segment number"+str(points[0])),outerboundaryis=[(float(points[2]),float(points[1])),(float(points[4]),float(points[3])),(float(points[6]),float(points[5])),(float(points[8]),float(points[7]))])
        poly.polystyle.outline=0
kml.save("overwrite1.kml")

我两次调用此代码示例,使用两个不同的文件,下面发布了其中的片段。文件 1:

90 17.44868272235051 78.35992655187812 17.448697277638573 78.35983344811831 17.448738277640214 78.35984044810797 17.44872372234887 78.35993355188845 
91 17.4486465880062 78.35986774305402 17.448733411989906 78.35989225695096 17.448203411899485 78.36194225741018 17.448116588096628 78.36191774259473 
92 17.44811737513277 78.36191508602762 17.44820262486316 78.3619449139783 17.447872624807378 78.36297491419779 17.447787375188554 78.36294508580814 
93 17.44778593144203 78.36295056347981 17.447874068554235 78.36296943652408 17.44777406853705 78.36347943664289 17.44768593145922 78.36346056336097 
94 17.447725298386487 78.3635168529482 17.44773470160246 78.36342314704976 17.448464701620733 78.36350314686737 17.448455298368216 78.36359685313049 
95 17.44844964150418 78.36359591532924 17.44847035848529 78.36350408466528 17.44916035852647 78.36367408449023 17.449139641463 78.36376591550432 
96 17.44914388953053 78.36376671292972 17.44915611045848 78.36367328706736 17.450066110488546 78.36380328683892 17.45005388950045 78.36389671315817 
97 17.45007148384362 78.36389560619496 17.450048516146023 78.36380439381118 17.45084851609243 78.36358439360971 17.450871483897217 78.36367560639643 
98 17.4508625677922 78.36367697298195 17.450857432196702 78.3635830270191 17.451527432187646 78.36354302685181 17.451532567801255 78.36363697314921 
99 17.45152818002525 78.3636369943884 17.45153181996366 78.36354300561091 17.454841819995337 78.36368300478371 17.45483817999356 78.36377699521559 

文件 2:

17473 17.44436514856338 78.47057386682884 17.444454851433058 78.47056613316957 17.444460851434094 78.470642133188 17.444371148562336 78.4706498668104 
17474 17.496817749620345 78.3936639958953 17.496902250375502 78.39369600411102 17.496642250331544 78.39444600426742 17.49655774966431 78.39441399573903 
17475 17.471726433843678 78.56706897439275 17.471793566150335 78.5671310256177 17.471353566083877 78.56765102565059 17.47128643391013 78.5675889743598 
17476 17.47585253344295 78.56776331893766 17.47588746654784 78.56767668105347 17.476727466633236 78.56804668087453 17.476692533357554 78.56813331911657 
17477 17.47712250351409 78.56712330514262 17.477157496476696 78.56703669484854 17.47860749662435 78.56767669454003 17.47857250336645 78.5677633054511 
17478 17.478630673594786 78.56773989598412 17.47854932640072 78.56770010402349 17.478849326351025 78.5670301041477 17.478930673644467 78.56706989586 
17479 17.478886419731488 78.56709693560659 17.478893580257395 78.56700306439186 17.479253580264213 78.56703306430197 17.479246419724667 78.56712693569652 
17480 17.47929464334328 78.56708587636851 17.47920535665311 78.56707412363394 17.479505356601035 78.5645841242342 17.479594643395355 78.5645958757682 
17481 17.48534674355407 78.56693717788423 17.485433256442004 78.56696282212097 17.485083256382193 78.56825282240784 17.484996743613884 78.56822717759738 
17482 17.485021447069396 78.56828279163804 17.485058552921615 78.56819720835271 17.485248552941915 78.56828720831444 17.4852114470491 78.56837279167631 

第一个 kml 文件的片段:

<tessellate>0</tessellate>
                        <extrude>0</extrude>
                        <coordinates>78.363676973,17.4508625678,0.0 78.363583027,17.4508574322,0.0 78.3635430269,17.4515274322,0.0 78.3636369731,17.4515325678,0.0</coordinates>
                    </LinearRing>
                </outerBoundaryIs>
            </Polygon>
            <styleUrl>#stylesel_98</styleUrl>
            <visibility>1</visibility>
            <open>0</open>
            <description>Segment number98</description>
        </Placemark>
        <Placemark id="feat_200">
            <Polygon id="geom_198">
                <tessellate>0</tessellate>
                <extrude>0</extrude>
                <outerBoundaryIs>
                    <LinearRing>
                        <tessellate>0</tessellate>
                        <extrude>0</extrude>
                        <coordinates>78.3636369944,17.45152818,0.0 78.3635430056,17.45153182,0.0 78.3636830048,17.45484182,0.0 78.3637769952,17.45483818,0.0</coordinates>
                    </LinearRing>
                </outerBoundaryIs>
            </Polygon>
            <styleUrl>#stylesel_99</styleUrl>
            <visibility>1</visibility>
            <open>0</open>
            <description>Segment number99</description>
        </Placemark>
    </Document>
</kml>

来自第二个 kml 文件的片段:

<tessellate>0</tessellate>
                        <extrude>0</extrude>
                        <coordinates>78.5669371779,17.4853467436,0.0 78.5669628221,17.4854332564,0.0 78.5682528224,17.4850832564,0.0 78.5682271776,17.4849967436,0.0</coordinates>
                    </LinearRing>
                </outerBoundaryIs>
            </Polygon>
            <styleUrl>#stylesel_98</styleUrl>
            <visibility>1</visibility>
            <open>0</open>
            <description>Segment number17481</description>
        </Placemark>
        <Placemark id="feat_200">
            <Polygon id="geom_198">
                <tessellate>0</tessellate>
                <extrude>0</extrude>
                <outerBoundaryIs>
                    <LinearRing>
                        <tessellate>0</tessellate>
                        <extrude>0</extrude>
                        <coordinates>78.5682827916,17.4850214471,0.0 78.5681972084,17.4850585529,0.0 78.5682872083,17.4852485529,0.0 78.5683727917,17.485211447,0.0</coordinates>
                    </LinearRing>
                </outerBoundaryIs>
            </Polygon>
            <styleUrl>#stylesel_99</styleUrl>
            <visibility>1</visibility>
            <open>0</open>
            <description>Segment number17482</description>
        </Placemark>
    </Document>
</kml>

生成的 kml 文件的快照,在两种情况下都相同 :( : [我什至在发出第二个请求之前清除了缓存]:

谢谢 。(对不起,描述太长了。但是,我希望他们把事情说清楚)

4

1 回答 1

3

Google Maps Caching KML上的 google 查询似乎表明 Google 正在缓存 KML 文件大约 5 分钟。

一个简单的解决方案是在您的 URL 中添加一个随机查询,因此http://maps.google.com/maps?q=http://<my ip>:8081/<location>/<name>.kml您可以链接到,而不是链接到http://maps.google.com/maps?q=http://<my ip>:8081/<location>/<name>.kml?rnd=<somerandomvalue>

您的网络服务器会忽略它,但 Google 会认为它是一个新 URL 并重新获取它。

于 2011-09-30T09:47:18.397 回答