2010-12-08 54 views

回答

1

對谷歌地圖實現多個位置首先你需要創建一個KML文件 例如: -

<?xml version="1.0" encoding="UTF-8"?> 
<kml xmlns="http://www.opengis.net/kml/2.2"> 
<Document> 
    <Placemark> 
    <name>Ottawa</name> 
    <description>Ottawa office</description> 
    <Point> 
    <coordinates>-90.86948943473118,48.25450093195546,0</coordinates> 
    </Point> 
    </Placemark> 
    <Placemark> 
    <name>Battel Creek</name> 
    <description>Battel Creek</description> 
    <Point> 
    <coordinates>-85.1220703125,42.35042512243457,0</coordinates> 
    </Point> 
    </Placemark> 

    </Document> 
</kml> 

保存在服務器上的文件(擴展名應該是KML),並設置在下面的代碼路徑: -

public void invokeGMaps() { 

     int mh = CodeModuleManager.getModuleHandle("GoogleMaps"); 
      if (mh == 0) { 
      try { 
      throw new ApplicationManagerException(
       "GoogleMaps isn't installed"); 
      } catch (ApplicationManagerException e) { 
      System.out.println(e.getMessage()); 
      } 
      } 
      String[] args = { };//PUT THE SAVED FILE URL OVER HERE IN DOUBLE QUOTES 
      ApplicationDescriptor ad = CodeModuleManager 
      .getApplicationDescriptors(mh)[0]; 
      ApplicationDescriptor ad2 = new ApplicationDescriptor(ad, args); 
      try { 
      ApplicationManager.getApplicationManager() 
      .runApplication(ad2, true); 
      } catch (ApplicationManagerException e) { 
      System.out.println(e.getMessage()); 
      } 
     } 

您需要先安裝谷歌地圖,然後再執行這些代碼。你可以從這裏下載谷歌地圖: - m.google.com/maps