How to show maps using GeoTools in Android?

别说谁变了你拦得住时间么 提交于 2019-12-11 01:24:45

问题


I am using Eclipse on Windows XP. I downloaded the GeoTools 2.7.4-bin.zip file and started to add some .jar files to my project. The particularity of my project is that this is an Android one.

I am developing an Android application that would allow me to show on a map (google map) some features (points but not only) so i tried to use GeoTools to do that.But Android is not supporting Swings. My code is

/*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);
    }

}

But it giving me following errors in eclipse

-The method showOpenFile(String, Component) from the type JFileDataStoreChooser refers to the missing type Component

  • The type java.awt.Component cannot be resolved. It is indirectly referenced from required .class files
  • The type java.awt.HeadlessException cannot be resolved. It is indirectly referenced from required .class files
  • The type javax.swing.JFileChooser cannot be resolved. It is indirectly referenced from required .class files
  • The method showMap(MapContext) in the type JMapFrame is not applicable for the arguments (MapContent)
  • The type javax.swing.JFrame cannot be resolved. It is indirectly referenced from required .class files Please any one help me to resolve these errors

回答1:


Unfortunately Swing is not implemented on Android, so you are out of luck. In fact Oracle and Google just fought a big legal battle that was partially about this. I'm pretty sure that porting any serious Swing app or library to Android is a major effort: almost a rewrite from scratch.



来源:https://stackoverflow.com/questions/11155885/how-to-show-maps-using-geotools-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!