android - 如何将标记添加到 Android 上的 ArcGIS map ?

标签 android map arcgis marker

我正在尝试在我的 Android 应用程序的 ArcGIS map 上添加标记。但是,添加图形层后,我的 map 并没有出现。我是 Android 应用程序编程的新手,非常感谢任何帮助。我不确定我在这里做错了什么。提前致谢。

这是我的代码:

public class SuggestionsFragment extends Fragment {
    MapView mMapView;
    GraphicsLayer graphicsLayer = new GraphicsLayer();
    Point point;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_suggestions,
            container, false);

    //Retrieve the map and initial extent from XML layout
    mMapView = (MapView)rootView.findViewById(R.id.map);

    //Create the layer
    final Layer oneMapLayer = new   ArcGISTiledMapServiceLayer("http://e1.onemap.sg/arcgis/rest/services/BASEMAP/MapServer");

    mMapView.addLayer(graphicsLayer);
    Point point = new Point(1.3799775, 103.84877200000005);
    graphicsLayer.addGraphic(new Graphic(point,new  SimpleMarkerSymbol(Color.RED,10,STYLE.CIRCLE)));

    //Know when the map layer loaded
    mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {
        private static final long serialVersionUID = 1L;

        public void onStatusChanged(Object source, STATUS status) {
            if (source == oneMapLayer && status == STATUS.LAYER_LOADED) {

                mMapView.centerAt(1.3799775, 103.84877200000005, false);
                mMapView.setScale(1500,false);


            }
        }
    });



    //Add dynamic layer to MapView
    mMapView.addLayer(oneMapLayer);




    return rootView;
}

@Override
public void onDestroy() {
    super.onDestroy();
}

@Override
public void onPause() {
    super.onPause();
    mMapView.pause();
}

@Override
public void onResume() {
    super.onResume();
    mMapView.unpause();
}

}

最佳答案

解决方法:

public class SuggestionsFragment2 extends Fragment {
MapView mMapView;
GraphicsLayer graphicsLayer = new GraphicsLayer();
Point point;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_suggestions2,
            container, false);



    //Retrieve the map and initial extent from XML layout
    mMapView = (MapView)rootView.findViewById(R.id.map);

    //Create the layer
    final Layer oneMapLayer = new ArcGISTiledMapServiceLayer("http://e1.onemap.sg/arcgis/rest/services/BASEMAP/MapServer");

    //Know when the map layer loaded
    mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {
        private static final long serialVersionUID = 1L;

        public void onStatusChanged(Object source, STATUS status) {
            if (source == oneMapLayer && status == STATUS.LAYER_LOADED) {

                mMapView.centerAt(1.3799775, 103.84877200000005, false);
                mMapView.setScale(1500,false);

                mMapView.addLayer(graphicsLayer);
                Point point = GeometryEngine.project(x, y, mMapView.getSpatialReference());
                graphicsLayer.addGraphic(new Graphic(point,new    SimpleMarkerSymbol(Color.RED,10,STYLE.CIRCLE)));

            }
        }

    });

    //Add dynamic layer to MapView
    mMapView.addLayer(oneMapLayer);

    return rootView;
}

@Override
public void onDestroy() {
    super.onDestroy();
}

@Override
public void onPause() {
    super.onPause();
    mMapView.pause();
}

@Override
public void onResume() {
    super.onResume();
    mMapView.unpause();
}

关于android - 如何将标记添加到 Android 上的 ArcGIS map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26272639/

相关文章:

java - 我需要 java 编程知识才能在 unity 3d 中开发 android 游戏吗?

java - ConcurrentModificationException 在 Java 中递归使用 Maps

android - Arcgis : how to get device location

c++ - 静态 std::map 的奇怪链接器错误

c# - 如何使用c#设置arcobjects中的输入和输出参数,调用python脚本?

python - 在 ArcMap 中运行 ExportReport Python 代码时出错

android - Android 是否支持所有 Unicode 字符

java - 我的 checkGPS 方法从未运行过,gps 保持 0.0,0.0

java - 我需要什么背景?

gis - 适用于基于服务的应用程序的开源 GIS 引擎