2013-03-20 79 views
2

如果您的.csv文件中包含地址信息,您可以將其拖放到Google Earth上(此後稱爲GE),然後會出現一個嚮導,您可以指定字段,然後GE將開始對併爲每個地址創建點(緯度和經度)。然後,您可以將地理編碼的文件導出爲kml,並獲取每個點的經緯度。但是該過程具有2500行的限制。如何在Google地球中創建kml到地理編碼地址?

我聽說可以創建一個kml(或者一個xml)文件並將其拉入GE以啓動地理編碼過程,並且此方法沒有行限制。有人可以幫助我弄清楚如何做到這一點?我已經嘗試了以下代碼,該代碼成功導入到GE中,但沒有創建點。

我知道一些Google Maps API可以做類似的事情,每天有超過100,000行的行數限制用於商業用途,但我真的很想讓這個過程與GE一起工作。

<?xml version="1.0" encoding="UTF-8"?> 
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> 
<Document> 
    <name>GEImport1.csv</name> 
    <Schema name="GEImport1" id="S_GEImport1_S"> 
     <SimpleField type="string" name="Adress"><displayName>&lt;b&gt;Adress&lt;/b&gt;</displayName> 
</SimpleField> 
    </Schema> 
    <Style id="hlightPointStyle"> 
     <IconStyle> 
      <Icon> 
       <href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle_highlight.png</href> 
      </Icon> 
     </IconStyle> 
     <BalloonStyle> 
      <text><![CDATA[<table border="0"> 
    <tr><td><b>Adress</b></td><td>$[GEImport1/Adress]</td></tr> 
</table> 
]]></text> 
     </BalloonStyle> 
    </Style> 
    <Style id="normPointStyle"> 
     <IconStyle> 
      <Icon> 
       <href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png</href> 
      </Icon> 
     </IconStyle> 
     <BalloonStyle> 
      <text><![CDATA[<table border="0"> 
    <tr><td><b>Adress</b></td><td>$[GEImport1/Adress]</td></tr> 
</table> 
]]></text> 
     </BalloonStyle> 
    </Style> 
    <StyleMap id="pointStyleMap"> 
     <Pair> 
      <key>normal</key> 
      <styleUrl>#normPointStyle</styleUrl> 
     </Pair> 
     <Pair> 
      <key>highlight</key> 
      <styleUrl>#hlightPointStyle</styleUrl> 
     </Pair> 
    </StyleMap> 
    <Folder id="layer 0"> 
     <name>GEImport1</name> 
     <visibility>0</visibility> 
     <Placemark> 
      <visibility>0</visibility> 
      <styleUrl>#pointStyleMap</styleUrl> 
      <ExtendedData> 
       <SchemaData schemaUrl="#S_GEImport1_S"> 
        <SimpleData name="Adress">6212 GATUN CT Port ST Lucie, FL</SimpleData> 
       </SchemaData> 
      </ExtendedData> 
     </Placemark> 
     <Placemark> 
      <visibility>0</visibility> 
      <styleUrl>#pointStyleMap</styleUrl> 
      <ExtendedData> 
       <SchemaData schemaUrl="#S_GEImport1_S"> 
        <SimpleData name="Adress">6213 DIANA CT Port ST Lucie, FL</SimpleData> 
       </SchemaData> 
      </ExtendedData> 
     </Placemark> 
     <Placemark> 
      <visibility>0</visibility> 
      <styleUrl>#pointStyleMap</styleUrl> 
      <ExtendedData> 
       <SchemaData schemaUrl="#S_GEImport1_S"> 
        <SimpleData name="Adress">6213 DUKE CIR Port ST Lucie, FL</SimpleData> 
       </SchemaData> 
      </ExtendedData> 
     </Placemark> 
    </Folder> 
</Document> 
</kml> 

編輯:最終結果
JasonM1的解決方案的工作太棒了! 我結束了對KML文件格式如下:

<?xml version="1.0" encoding="UTF-8"?> 
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> 
    <Document> 
<name>AddressImport</name> 
    <Style id="normPointStyle"> 
     <IconStyle> 
      <Icon> 
       <href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png</href> 
      </Icon> 
     </IconStyle> 
     <BalloonStyle> 
      <text><![CDATA[<table border="0"> 
      <tr><td><b>Address</b></td><td>$[address]</td></tr> 
      </table>]]> 
     </text> 
     </BalloonStyle> 
    </Style> 
    <StyleMap id="pointStyleMap"> 
     <Pair> 
      <key>normal</key> 
      <styleUrl>#normPointStyle</styleUrl> 
     </Pair> 
    </StyleMap> 
    <Folder id="layer 0"> 
     <name>AddressImport</name> 
     <visibility>1</visibility> 
     <Placemark> 
      <visibility>1</visibility> 
      <address>9994 CHADWICK DR Port ST Lucie, FL</address> 
      <styleUrl>#pointStyleMap</styleUrl> 
     </Placemark> 
     <Placemark> 
      <visibility>1</visibility> 
      <address>9995 AMBROSE WAY Port ST Lucie, FL</address> 
      <styleUrl>#pointStyleMap</styleUrl> 
     </Placemark> 
     <Placemark> 
      <visibility>1</visibility> 
      <address>9997 STONEGATE DR Port ST Lucie, FL</address> 
      <styleUrl>#pointStyleMap</styleUrl> 
     </Placemark> 
    </Folder> 
</Document> 
</kml> 

另外,我用下面的Excel VBA代碼來自動創建KML文件:

Sub CreateCSV_FSO() 
    Dim objFSO 
    Dim objTF 
    Dim ws As Worksheet 
    Dim lRow As Long 
    Dim lCol As Long 
    Dim strTmp As String 
    Dim lFnum As Long 
    Dim sFilePath As String 
    Dim i As Long 
    Dim x As Integer 'used to represent the column that contains the address 
    sFilePath = ActiveWorkbook.Path & "\AddressImport.kml" 

    Set objFSO = CreateObject("scripting.filesystemobject") 
    Set objTF = objFSO.createtextfile(sFilePath, True, False) 

    'Header information 
    objTF.writeline "<?xml version=""1.0"" encoding=""UTF-8""?>" 
    objTF.writeline "<kml xmlns=""http://www.opengis.net/kml/2.2"" xmlns:gx=""http://www.google.com/kml/ext/2.2"" xmlns:kml=""http://www.opengis.net/kml/2.2"" xmlns:atom=""http://www.w3.org/2005/Atom"">" 
    objTF.writeline " <Document>" 
    objTF.writeline "<name>AddressImport</name>" 
    objTF.writeline " <Style id=""normPointStyle"">" 
    objTF.writeline "  <IconStyle>" 
    objTF.writeline "   <Icon>" 
    objTF.writeline "    <href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png</href>" 
    objTF.writeline "   </Icon>" 
    objTF.writeline "  </IconStyle>" 
    objTF.writeline "  <BalloonStyle>" 
    objTF.writeline "   <text><![CDATA[<table border=""0"">" 
    objTF.writeline "   <tr><td><b>Address</b></td><td>$[address]</td></tr>" 
    objTF.writeline "   </table>]]>" 
    objTF.writeline "  </text>" 
    objTF.writeline "  </BalloonStyle>" 
    objTF.writeline " </Style>" 
    objTF.writeline " <StyleMap id=""pointStyleMap"">" 
    objTF.writeline "  <Pair>" 
    objTF.writeline "   <key>normal</key>" 
    objTF.writeline "   <styleUrl>#normPointStyle</styleUrl>" 
    objTF.writeline "  </Pair>" 
    objTF.writeline " </StyleMap>" 
    objTF.writeline " <Folder id=""layer 0"">" 
    objTF.writeline "  <name>AddressImport</name>" 
    objTF.writeline "  <visibility>1</visibility>" 

    'input the number representative of the column that contains the address 
    x = 7 'a=1,b=2,c=3,d=4.....etc. 
    i = 2 
    While Cells(i, x) <> "" 

     strTmp = "" 
     strTmp = Cells(i, x) 
     strTmp = Replace(strTmp, "&", "and") 

     objTF.writeline "  <Placemark>" 
     objTF.writeline "   <visibility>1</visibility>" 
     objTF.writeline "   <address>" & strTmp & "</address>" 
     objTF.writeline "   <styleUrl>#pointStyleMap</styleUrl>" 
     objTF.writeline "  </Placemark>" 


     strTmp = Cells(i, x) 
     i = i + 1 
    Wend 

    objTF.writeline " </Folder>" 
    objTF.writeline "</Document>" 
    objTF.writeline "</kml>" 


    objTF.Close 
    Set objFSO = Nothing 
    MsgBox "Done!", vbOKOnly 

End Sub 

回答

2

使用< address>元素Google地球將自動地爲您編碼地址。

<Placemark> 
    <visibility>0</visibility> 
    <address>6213 DUKE CIR Port ST Lucie, FL</address> 
    <styleUrl>#pointStyleMap</styleUrl>    
</Placemark> 

您可以使用<address>標籤可以指定點,而不是使用緯度和經度座標的位置。 (但是,如果提供<Point>,它優先於<address>

另外,您不再需要架構和ADRESS SchemaData要素,而是可直接內聯$ [地址]字段中BalloonStyle中文字:

<BalloonStyle> 
     <text><![CDATA[<table border="0"> 
      <tr><td><b>Adress</b></td><td>$[address]</td></tr> 
      </table>]]> 
     </text> 
</BalloonStyle> 

後加載在谷歌地球KML文件並保存它,你會發現,谷歌地球將其更改爲與座標下面填寫的:

<Placemark> 
    <address>6213 DUKE CIR Port ST Lucie, FL</address> 
    <styleUrl>#pointStyleMap</styleUrl> 
    <MultiGeometry> 
     <Point> 
      <coordinates>-80.36086,27.366379,0</coordinates> 
     </Point> 
     <LinearRing> 
      <coordinates> 
       -80.36086,27.366379,0 -80.36086,27.366379,0 -80.36086,27.366379,0 -80.36086,27.366379,0 -80.36086,27.366379,0 
      </coordinates> 
     </LinearRing> 
    </MultiGeometry> 
</Placemark>