2
我在Windows XP上使用Eclipse。我下載了GeoTools 2.7.4-bin.zip文件,並開始將一些.jar文件添加到我的項目中。 我的項目的特殊之處在於這是一款Android系統。如何在Android中使用GeoTools顯示地圖?
我正在開發一個Android應用程序,它允許我在地圖上顯示一些功能(但不僅僅是點),所以我嘗試使用GeoTools來做到這一點。但Android不支持Swings。 我的代碼是
/*code i m using */
package info.ipower.geotools;
import java.io.File;
import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.data.JFileDataStoreChooser;
/**
* Prompts the user for a shapefile and displays the contents on the screen in a map frame.
* <p>
* This is the GeoTools MapApplication application used in documentationa and tutorials. *
*/
public class GeoMap{
/**
* GeoTools MapApplication demo application. Prompts the user for a shapefile and displays its
* contents on the screen in a map frame
*/
public static void main(String[] args) throws Exception {
// display a data store file chooser dialog for shapefiles
File file = JFileDataStoreChooser.showOpenFile("shp", null);
if (file == null) {
return;
}
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
// Create a map content and add our shapefile to it
MapContent map = new MapContent();
map.setTitle("MapApplication");
Style style = SLD.createSimpleStyle(featureSource.getSchema());
Layer layer = new FeatureLayer(featureSource, style);
map.addLayer(layer);
// Now display the map
JMapFrame.showMap(map);
}
}
但它給了我下面的日食錯誤
從類型JFileDataStoreChooser -The方法showOpenFile(字符串,組件)是指 的缺失型組件
- 的類型java.awt.Component不能被解析。它是從 間接引用的.class文件
- 無法解析java.awt.HeadlessException類型。它是從所需的.class文件中引用的間接
- 無法解析類型javax.swing.JFileChooser。這是間接地從 需要.class文件引用
- 在類型JMapFrame方法showMap(MapContext)不 適用於參數(MapContent)
- 類型javax.swing.JFrame中不能得到解決。這是間接 從所需的.class文件中引用 請任何一個可以幫助我解決這些錯誤
Thanku給我回復。但是有可能使用Swing概念顯示沒有外形的文件嗎? – pravallika
錯誤消息表明您嘗試使用的地理工具部分預計會使用AWT和Swing。 AWT和Swing不屬於Android。所以肯定你不能使用庫的那部分。也許其他部分是可用的。我不能說。 – Gene
那麼,在android中有沒有其他的方法來顯示形狀文件?請幫助我。 – pravallika