Arcgis:地图上的多个引脚

时间:2013-11-06 01:49:55

标签: java arcgis esri

嗨,

我想在地图上放置多个图钉。目前,我在地图上显示了一个图钉。我尝试编写多个位置名称,但只加载一个位置.. 这是我的代码。

public class test extends Activity {
MapView mMapView = null;
ArcGISTiledMapServiceLayer mapLayer;
GraphicsLayer grahpicslayer = new GraphicsLayer();


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Geocoder gc = new Geocoder(this, Locale.getDefault());

    try {
        String locationName = "";

        //Change this to respective library
        //The library name get from the NLB rss feed from the previous page
        //pin 1
        locationName = "Bishan Public Library";

        //pin2
        locationName = "Hougang";

        //pin3
        locationName = "Sengkang";

        //get list of address base on location name
        List<Address> list = gc.getFromLocationName(locationName,1);

        //get the first result appear on the list
        Address address = list.get(0);

        //get the latitude of that address
        double lat = address.getLatitude();
        //get the longitude of that address
        double lng = address.getLongitude();


        // Retrieve the map and initial extent from XML layout
        mMapView = (MapView)findViewById(R.id.map);
        /* create a @ArcGISTiledMapServiceLayer */
        mapLayer = new ArcGISTiledMapServiceLayer(
                //"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
                "http://e1.onemap.sg/ArcGIS/rest/services/SM128/MapServer");

        // Add tiled layer to MapView
        mMapView.addLayer(mapLayer);


        SpatialReference worldMap = SpatialReference.create(4326);
        SpatialReference oneMap = SpatialReference.create(3414);

        //Set the point to the longitude and latitude 
        Point point = new Point(lng,lat);
        //Point point = new Point(103.799598,1.443603);

        //Change world spatial reference to one map reference
        Point oneMapPoint = (Point) GeometryEngine.project(point, worldMap, oneMap);

        //create red color diamond graphics
        grahpicslayer.addGraphic(new Graphic(oneMapPoint,new SimpleMarkerSymbol(Color.RED,20,STYLE.CIRCLE)));

        //Display the red color diamond graphics
        mMapView.addLayer(grahpicslayer);

        //zoom the map to the location
        mMapView.zoomToResolution(oneMapPoint, 0);

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println("Error");
    }

}

1 个答案:

答案 0 :(得分:0)

您只需拨打addGraphic一次,所以当然您只能获得一张图片。

对于每个地名,您需要进行地理编码,创建和投影点,以及创建和添加图形。现在,你只为一个地名做这些事:“Sengkang”。使用地名数组和for循环。更好的是,制作一个方法并调用它三次。

相关问题