How to add marker or graphics to MapView using ArcGIS android SDK?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 04:02:22

问题


I'm trying to add some markers or graphic to my Map using graphicsLayer, but I can't show them.

This is my .geodatabase file converted from .shp file using ArcMap: http://1drv.ms/1OwrRm0

Could anyone help me! QQ

Thanks in advance.

Here is my code:

package com.example.root.map;
import android.net.Uri;
import android.os.Bundle;
import com.esri.android.map.MapView;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;


import android.app.Activity;
import com.esri.android.map.*;
import com.esri.android.map.FeatureLayer;
import com.esri.android.map.GraphicsLayer;
import com.esri.core.geodatabase.Geodatabase;
import com.esri.core.geodatabase.GeodatabaseFeature;
import com.esri.core.geodatabase.GeodatabaseFeatureTable;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.Point;
import com.esri.core.map.Graphic;
import com.esri.core.renderer.SimpleRenderer;
import com.esri.core.symbol.SimpleMarkerSymbol;
import com.esri.core.table.TableException;
import com.google.android.gms.appindexing.Action;
import android.graphics.Color;
import android.util.Log;


public class MainActivity extends Activity {
static final String TAG = "GGININDER";
MapView mMapView;
Geodatabase geodatabase;
GeodatabaseFeatureTable geodatabaseFeatureTable4, geodatabaseFeatureTable1, geodatabaseFeatureTable2, geodatabaseFeatureTable3;
FeatureLayer  featureLayer1, featureLayer2, featureLayer3, featureLayer4;

GraphicsLayer graphicsLayer;
Graphic pointGraphic;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Open the geodatabase file
    Geodatabase geodatabase, geodatabase1, geodatabase2, geodatabase3,geodatabase4;

    try {
        mMapView = (MapView) findViewById(R.id.map);
        geodatabase1 = new Geodatabase("/sdcard/Download/1.geodatabase");
        geodatabase2 = new Geodatabase("/sdcard/Download/2.geodatabase");
        geodatabase3 = new Geodatabase("/sdcard/Download/3.geodatabase");
        geodatabase4 = new Geodatabase("/sdcard/Download/4.geodatabase");


        //get the geodatabase feature table
        geodatabaseFeatureTable1 = geodatabase1.getGeodatabaseFeatureTableByLayerId(0);
        geodatabaseFeatureTable2 = geodatabase2.getGeodatabaseFeatureTableByLayerId(0);
        geodatabaseFeatureTable3 = geodatabase3.getGeodatabaseFeatureTableByLayerId(0);
        geodatabaseFeatureTable4 = geodatabase4.getGeodatabaseFeatureTableByLayerId(0);
        //create a feature layer



        featureLayer1 = new FeatureLayer(geodatabaseFeatureTable1);
        featureLayer2 = new FeatureLayer(geodatabaseFeatureTable2);
        featureLayer3 = new FeatureLayer(geodatabaseFeatureTable3);
        featureLayer4 = new FeatureLayer(geodatabaseFeatureTable4);
        //featureLayer3 = new FeatureLayer(null);



        mMapView.addLayer(featureLayer1);
        mMapView.addLayer(featureLayer2);
        mMapView.addLayer(featureLayer3);
        mMapView.addLayer(featureLayer4);


        SimpleMarkerSymbol simpleMarker = new SimpleMarkerSymbol(Color.RED, 20, SimpleMarkerSymbol.STYLE.CROSS);
        graphicsLayer = new GraphicsLayer();
        Point point = new Point(5,5);
        pointGraphic = new Graphic(point, simpleMarker);
        graphicsLayer.addGraphic(pointGraphic);
        mMapView.addLayer(graphicsLayer);


    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
}

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

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

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

@Override
public void onStart() {
    super.onStart();

    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    Action viewAction = Action.newAction(
            Action.TYPE_VIEW, // TODO: choose an action type.
            "Main Page", // TODO: Define a title for the content shown.
            // TODO: If you have web page content that matches this app activity's content,
            // make sure this auto-generated web page URL is correct.
            // Otherwise, set the URL to null.
            Uri.parse("http://host/path"),
            // TODO: Make sure this auto-generated app deep link URI is correct.
            Uri.parse("android-app://com.example.root.map/http/host/path")
    );
}

@Override
public void onStop() {
    super.onStop();

    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    Action viewAction = Action.newAction(
            Action.TYPE_VIEW, // TODO: choose an action type.
            "Main Page", // TODO: Define a title for the content shown.
            // TODO: If you have web page content that matches this app activity's content,
            // make sure this auto-generated web page URL is correct.
            // Otherwise, set the URL to null.
            Uri.parse("http://host/path"),
            // TODO: Make sure this auto-generated app deep link URI is correct.
            Uri.parse("android-app://com.example.root.map/http/host/path")
    );

}
}

回答1:


Just change your coordinates:

Point point = new Point(121.5, 24);

Your geodatabase features are all in Taiwan, but (5, 5) is not. When I use your code with (121.5, 24), I see a red cross graphic on the map.




回答2:


GoogleMap map;
    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    map.addMarker(new MarkerOptions()
            .position(new LatLng(0, 0))
            .title("Hello world"));
}

https://developers.google.com/maps/documentation/android-api/marker code to add markers to map using android google maps v2



来源:https://stackoverflow.com/questions/34041489/how-to-add-marker-or-graphics-to-mapview-using-arcgis-android-sdk

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