在Google Map Android上添加了缩放KML图层

时间:2018-07-18 18:49:14

标签: android google-maps kml

我正在努力在Google地图上添加KML图层。该图层已正确添加到地图上,但我需要手动缩放到添加的图层。我希望该图层以我发现的可接受的缩放级别显示地标的“ Lat Long”。那么,如何正确迭代KML层?

这是我的KML文件的简短版本:-

    <?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="root_doc">
<Folder><name>Cadastral</name>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.2069037838963,19.6532892598215 76.2065130119793,19.6533251536786 76.2069037836869,19.6532892599407 76.2069037838963,19.6532892598215</coordinates></LinearRing></outerBoundaryIs></Polygon><Polygon><outerBoundaryIs><LinearRing><coordinates>76.2035162366371,19.6534789527307 76.2034551982285,19.6534374613985 76.2030092870386,19.6531346168346 76.2034551976626,19.6534374611314 76.2035162366371,19.6534789527307</coordinates></LinearRing></outerBoundaryIs></Polygon><Polygon><outerBoundaryIs><LinearRing><coordinates>76.2004816213987,19.651368561793 76.2004773434071,19.6513649499203 76.2004773434078,19.6513649499312 76.2004816213987,19.651368561793</coordinates></LinearRing></outerBoundaryIs></Polygon><Polygon><outerBoundaryIs><LinearRing><coordinates>76.199598484157,19.6464440709619 76.1991987805021,19.646073753751 76.1987011454855,19.6460640186678 76.1991987805549,19.6460737540581 76.199598484157,19.6464440709619</coordinates></LinearRing></outerBoundaryIs></Polygon><Polygon><outerBoundaryIs><LinearRing><coordinates>76.1949216430899,19.6459906098212 76.1938980555816,19.6459707627673 76.1936579088486,19.6460669755877 76.1936579087793,19.6460669756147 76.1936579089746,19.646066976266 76.1938980563696,19.6459707629758 76.1949216430899,19.6459906098212</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.1936579087793,19.6460669756147 76.1936579088486,19.6460669755877 76.1935002574836,19.6455413047645 76.1934641032028,19.6454214740334 76.1934641025377,19.645421474316 76.1935002566718,19.6455413051674 76.1936579087793,19.6460669756147</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.206649979891,19.6526549784311 76.2059206621402,19.6527272709345 76.203832676777,19.6528849704506 76.202664600143,19.6520571404576 76.2012284100803,19.6511271803403 76.2012678986018,19.6496809534094 76.2013029669683,19.6490595565394 76.2013733468034,19.6488737984938 76.2015677115904,19.6483622587725 76.2012470388229,19.6471126222714 76.1994175752593,19.6455724243041 76.1981114854285,19.6454567532344 76.1970983219057,19.6454042605993 76.1966786304737,19.6453821086074 76.1962691087218,19.6453407636987 76.1959033351051,19.6453407313657 76.1955471148495,19.6453328045389 76.1950442409487,19.6453172923611 76.1943278144018,19.6453635737196 76.1935058427228,19.6454187179694 76.1934641032028,19.6454214740334 76.1935002574836,19.6455413047645 76.1936579088486,19.6460669755877 76.1938980555816,19.6459707627673 76.1949216430899,19.6459906098212 76.1978135327655,19.6460466505968 76.1987011454855,19.6460640186678 76.1991987805021,19.646073753751 76.199598484157,19.6464440709619 76.2004913584689,19.6472712903185 76.2004051231478,19.6502157105696 76.2004773434071,19.6513649499203 76.2004816213987,19.651368561793 76.2007803773768,19.6516207975801 76.2030092870386,19.6531346168346 76.2034551982285,19.6534374613985 76.2035162366371,19.6534789527307 76.203673462356,19.6535858276305 76.2037882561211,19.6535752758867 76.2041403889194,19.6535430688587 76.2065130119793,19.6533251536786 76.2069037838963,19.6532892598215 76.2100468872145,19.6515010149398 76.2112143891479,19.6510971936268 76.21188197637,19.6508547327688 76.2122986946843,19.6507034045507 76.2177774231825,19.6487124226774 76.2179284400117,19.6485038739375 76.2185542706224,19.6476396172347 76.2186295806274,19.6475358793931 76.2186480896452,19.647510383459 76.2194111827185,19.6464567611353 76.2194538175326,19.6457252046739 76.219577133607,19.6436005817332 76.2195846247514,19.6434719587805 76.2195866418614,19.6434373228242 76.2199756168119,19.6418243874326 76.2199756168404,19.641824387415 76.2199756170265,19.6418243866433 76.2206095753725,19.6414328415192 76.2208561901911,19.6412805260191 76.2226700756087,19.6404483624118 76.2233957702044,19.6401154250567 76.2242557229484,19.6399054967446 76.2286242887495,19.6388389877058 76.2320938352874,19.6376431337265 76.2329546228485,19.6373464316513 76.2335126485726,19.6371540176621 76.234259250098,19.6368967580873 76.2354083146196,19.636500811579 76.2390572817019,19.6343054605676 76.2404573603072,19.6327356673609 76.2409897613338,19.6321387192365 76.2410603237359,19.6306156800405 76.2413179850421,19.6304650464407 76.242060063909,19.6300312087018 76.2418874759097,19.6293503295825 76.2417699707574,19.6288867556756 76.2418864928975,19.6286121073921 76.2418902243032,19.628603312242 76.2419207388605,19.6285313682379 76.2436171016635,19.6245317597568 76.2436898997892,19.6243699716448 76.2437166896782,19.6243104325038 76.2437226703765,19.6242974467616 76.2433967743718,19.6241710089743 76.2433303433282,19.6241454935613 76.2432935856706,19.6242092832835 76.2429427444997,19.6248161328225 76.2429158489142,19.6248624225221 76.2414320973596,19.6274089073805 76.240845708575,19.6284470549338 76.2408719876621,19.6286120607581 76.2409487310153,19.6291121598702 76.2409788383098,19.629308243913 76.2410467270918,19.6297507042988 76.241144720486,19.6303915083357 76.2408376741141,19.6308029366301 76.2405198731872,19.63122903831 76.2393435519153,19.6328623872074 76.2382114930468,19.6338003229434 76.2380660734689,19.633965651209 76.2368585209541,19.6347509323149 76.2360895844206,19.6352509599893 76.2356607889668,19.6355396092644 76.2345551606438,19.6361323688995 76.2344221226549,19.63619093437 76.234196912446,19.6362900448524 76.2339774173982,19.6363558305837 76.2337814807701,19.6364154353057 76.2336568221303,19.6364525437574 76.2334218190622,19.6365228262615 76.2332437620529,19.6365858458833 76.2327468733148,19.6367608334405 76.2316439462193,19.6371400247302 76.2306353802221,19.6374114391527 76.229846329938,19.6376040734657 76.229143279441,19.6378894835191 76.227797029336,19.6383095391688 76.2263382590881,19.6386260316936 76.2256226176432,19.6387633905446 76.2251171943021,19.6388609459121 76.2248107176364,19.6388842202051 76.2240890428876,19.6390645012992 76.2234856400923,19.6392878927697 76.2231774930463,19.6394218940874 76.2229818033853,19.6395086060722 76.2228007292366,19.6395896900727 76.2226515746888,19.6396561326195 76.222520054209,19.6396937884474 76.2221796437615,19.6398695469405 76.2219233721638,19.639997974201 76.2209463359326,19.6404744645926 76.2197874827385,19.6409342918502 76.2195807557743,19.6412057253852 76.2194570999366,19.6415366048803 76.2190359100391,19.6426139104974 76.2190281107409,19.6430071101943 76.2190250278184,19.6430692510194 76.2190043829992,19.6436607317588 76.2189849943905,19.6442132320879 76.2189930242628,19.6449516451045 76.218822784386,19.6456920479557 76.2183132091485,19.6466680886562 76.2180382806268,19.6470755712622 76.2175128291055,19.6477312540839 76.2168430643306,19.6480409613055 76.216308219941,19.6482435302243 76.2160910532409,19.6485098585272 76.2147528670957,19.6490303948856 76.2140741875938,19.6493169152681 76.2128010766701,19.6497782173387 76.2112628213317,19.6503080239363 76.2103244788669,19.6507681340833 76.2099144673162,19.6510064715833 76.2084990727168,19.6516776864646 76.2078408833712,19.6519986788093 76.206649979891,19.6526549784311</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.203832676777,19.6528849704506 76.2040017109669,19.6520214208476 76.2051261194667,19.6517237797635 76.2046992910019,19.6496067733563 76.203653296257,19.6461153653449 76.2027616842875,19.6464467031125 76.2033528184164,19.6483459054328 76.2035753904903,19.649446232596 76.2036715345249,19.6500475003789 76.2038072078857,19.6505460087028 76.2012284100803,19.6511271803403 76.202664600143,19.6520571404576 76.203832676777,19.6528849704506</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.206649979891,19.6526549784311 76.2063128095002,19.6514380944697 76.206052433059,19.6508145355829 76.2055726679388,19.6486183525181 76.2054692371471,19.6480905182771 76.204637356954,19.6459338841538 76.2043831671967,19.6448431105053 76.2035103683613,19.6449880455415 76.203653296257,19.6461153653449 76.2046992910019,19.6496067733563 76.2051261194667,19.6517237797635 76.2040017109669,19.6520214208476 76.203832676777,19.6528849704506 76.2059206621402,19.6527272709345 76.206649979891,19.6526549784311</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.2078408833712,19.6519986788093 76.2074513044982,19.6509173038382 76.2073350547875,19.6500363527726 76.2069985220991,19.6479240116655 76.2069927050292,19.6471421007933 76.2064546616646,19.6455531547689 76.2063373379863,19.64443435162 76.2051000610476,19.644695664482 76.2043831671967,19.6448431105053 76.204637356954,19.6459338841538 76.2054692371471,19.6480905182771 76.2055726679388,19.6486183525181 76.206052433059,19.6508145355829 76.2063128095002,19.6514380944697 76.206649979891,19.6526549784311 76.2078408833712,19.6519986788093</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.1534204299819,19.6432503554705 76.1533487743626,19.6430823167851 76.1533487736688,19.6430823168349 76.153348773785,19.6430823174124 76.1534204299819,19.6432503554705</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.2084990727168,19.6516776864646 76.2086821119209,19.6502774449894 76.2085262221183,19.647636024353 76.2082815052741,19.6462181608687 76.2080736976322,19.6443105349471 76.2079714815899,19.6442911658396 76.2065430455444,19.6442504998144 76.206332036522,19.6440490413895 76.2063322174257,19.6441174016873 76.2063373379863,19.64443435162 76.2064546616646,19.6455531547689 76.2069927050292,19.6471421007933 76.2069985220991,19.6479240116655 76.2073350547875,19.6500363527726 76.2074513044982,19.6509173038382 76.2078408833712,19.6519986788093 76.2084990727168,19.6516776864646</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.2103244788669,19.6507681340833 76.2100944778193,19.6503316286977 76.2100408790098,19.6495908861755 76.2099159862946,19.6481732129382 76.2097939259075,19.6470205084309 76.2097570112581,19.6464628371875 76.2094512483053,19.6442985688173 76.2091087077189,19.6443110272318 76.2080736976322,19.6443105349471 76.2082815052741,19.6462181608687 76.2085262221183,19.647636024353 76.2086821119209,19.6502774449894 76.2084990727168,19.6516776864646 76.2099144673162,19.6510064715833 76.2103244788669,19.6507681340833</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.1714705883157,19.6478897933864 76.1714035127461,19.6478984987578 76.171334493725,19.6479074243193 76.1714035131207,19.6478984987206 76.1714705883157,19.6478897933864</coordinates></LinearRing></outerBoundaryIs></Polygon><Polygon><outerBoundaryIs><LinearRing><coordinates>76.169525443607,19.6481562830799 76.1693185741097,19.6481902857057 76.1693185741164,19.6481902858026 76.1693185744483,19.6481902857494 76.169525443607,19.6481562830799</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.1693185741164,19.6481902858026 76.1693185741097,19.6481902857057 76.1690990977958,19.6482254887052 76.1684429464766,19.6482322326011 76.1679579072896,19.6482552819427 76.1684429461136,19.6482322331603 76.1690990978269,19.648225489092 76.1693185741164,19.6481902858026</coordinates></LinearRing></outerBoundaryIs></Polygon><Polygon><outerBoundaryIs><LinearRing><coordinates>76.1678183164823,19.6482620471213 76.1676826972571,19.6482687315325 76.1670572058313,19.6482986885642 76.1670572058404,19.6482986887953 76.1670572059567,19.6482986887977 76.167682697016,19.6482687316773 76.1678183164823,19.6482620471213</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.1670572058404,19.6482986887953 76.1670572058313,19.6482986885642 76.167021686998,19.6482979396533 76.1670572058404,19.6482986887953</coordinates></LinearRing></outerBoundaryIs></Polygon><Polygon><outerBoundaryIs><LinearRing><coordinates>76.1662517906804,19.6482821993897 76.1660275773746,19.6482776390339 76.1658280067491,19.6482736629194 76.1660275774077,19.6482776392798 76.1662517906804,19.6482821993897</coordinates></LinearRing></outerBoundaryIs></Polygon><Polygon><outerBoundaryIs><LinearRing><coordinates>76.1652763138959,19.6482595731148 76.1652689261943,19.6482587653202 76.1651263902063,19.6482434166805 76.1652689260127,19.6482587654343 76.1652763138959,19.6482595731148</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.1199300008176,19.5818115764893 76.121090652073,19.5815574344241 76.1210906518553,19.5815574339677 76.1199300005316,19.5818115759265 76.1199300001619,19.5818115766337 76.1199300008176,19.5818115764893</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.1225313524288,19.5814331709258 76.1228154704127,19.581406685287 76.1234538999981,19.5813480854173 76.1235309732522,19.5813417558669 76.1234538996664,19.5813480849343 76.122815470266,19.581406684721 76.1225313524288,19.5814331709258</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
  <Placemark>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
      <MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>76.1210906518553,19.5815574339677 76.121090652073,19.5815574344241 76.1211073661297,19.5815561104587 76.1210906524672,19.5815574338337 76.1210906518553,19.5815574339677</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
  </Placemark>
</Folder>
</Document></kml>

我尝试使用下面的代码放大该图层:

//First container in the kmlLayer
KmlContainer container = kmlLayer.getContainers().iterator().next();
//first nested container within the first container
container = container.getContainers().iterator().next();
//First placemark in the nested container
KmlPlacemark placemark = container.getPlacemarks().iterator().next();
Toast.makeText(this, ""+placemark, Toast.LENGTH_SHORT).show();
placemark.getProperty("latitude");
placemark.getProperty("longitude");
Toast.makeText(this, ""+placemark.getProperty("latitude"), Toast.LENGTH_SHORT).show();
Toast.makeText(this, ""+placemark.getProperty("longitude"), Toast.LENGTH_SHORT).show();

但是Lat-Long为空。 我尝试了此Google Maps API Zoom to fit KmlLayer,但KmlGeometry似乎丢失了(无法解决)。更改为KMLMultiGeometry并没有解决问题。

0 个答案:

没有答案