2011-09-30 128 views
0

我生成KML文件。生成後,我會像這樣調用Google地圖:無法覆蓋kml文件

http://maps.google.com/maps?q=http://<my ip>:8081/<location>/<name>.kml。我使用的文件名基於用戶輸入的起始位置的緯度/經度。顯然,當位置相同時,將從相同的位置開始生成新的kml文件。在這種情況下,舊的應該被覆蓋,這是。但是,當它提供給Google地圖時,Google地圖會顯示舊文件。我從兩個示例文件和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文件生成,在這兩種情況下相同:(:[我甚至在發出第二次請求之前清除緩存]:

謝謝。 (對不起,我希望他們說清楚)

回答

2

Google Maps Caching KML的google查詢似乎表明Google正在緩存KML文件約5分鐘。

一個簡單的解決方案是一個隨機查詢添加到您的網址,這樣反而鏈接到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>

您的Web服務器會忽略它,但谷歌會認爲這是一個新的URL和重取它。

+0

非常感謝!我會試試這個並回復你。謝謝 – crazyaboutliv