如何使用ArcGIS android SDK将标记或图形添加到MapView?

时间:2015-12-02 11:21:32

标签: android arcgis

我正在尝试使用graphicsLayer为我的地图添加一些标记或图形, 但是我不能给他们看。

这是我使用ArcMap从.shp文件转换的.geodatabase文件: http://1drv.ms/1OwrRm0

任何人都可以帮助我! QQ

提前致谢。

这是我的代码:

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")
    );

}
}

2 个答案:

答案 0 :(得分:0)

只需更改坐标:

Point point = new Point(121.5, 24);

您的地理数据库功能全部在台湾,但(5,5)不是。当我使用你的代码(121.5,24)时,我在地图上看到一个红色的十字图形。

答案 1 :(得分:-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