Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Arcgis:地图上的多个管脚_Java_Arcgis_Esri - Fatal编程技术网

Java Arcgis:地图上的多个管脚

Java Arcgis:地图上的多个管脚,java,arcgis,esri,Java,Arcgis,Esri,嗨 我想在地图上放多个大头针。目前,我有一个pin显示在地图上。我尝试写入多个位置名称,但它只加载一个位置。。 这是我的密码 public class test extends Activity { MapView mMapView = null; ArcGISTiledMapServiceLayer mapLayer; GraphicsLayer grahpicslayer = new GraphicsLayer(); /** Called when the activity is fir

我想在地图上放多个大头针。目前,我有一个pin显示在地图上。我尝试写入多个位置名称,但它只加载一个位置。。 这是我的密码

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

}
公共类测试扩展活动{
MapView mMapView=null;
ArcGISTiledMapServiceLayer映射层;
GraphicsLayer grahpicslayer=新GraphicsLayer();
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Geocoder gc=新的Geocoder(这个,Locale.getDefault());
试一试{
字符串locationName=“”;
//将此更改为相应的库
//从上一页的NLB rss源获取的库名称
//引脚1
locationName=“璧山公共图书馆”;
//pin2
locationName=“后港”;
//pin3
locationName=“圣康”;
//根据位置名称获取地址列表
List List=gc.getFromLocationName(locationName,1);
//获取列表上显示的第一个结果
地址=list.get(0);
//获取该地址的纬度
双lat=地址。getLatitude();
//获取该地址的经度
double lng=address.getLongitude();
//从XML布局检索地图和初始范围
mMapView=(MapView)findViewById(R.id.map);
/*创建@ArcGISTiledMapServiceLayer*/
mapLayer=新的ArcGISTiledMapServiceLayer(
//"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
"http://e1.onemap.sg/ArcGIS/rest/services/SM128/MapServer");
//将平铺图层添加到MapView
mMapView.addLayer(mapLayer);
SpatialReference worldMap=SpatialReference.create(4326);
SpatialReference oneMap=SpatialReference.create(3414);
//将点设置为经度和纬度
点=新点(lng、lat);
//点=新点(103.799598,1.443603);
//将世界空间参照更改为一个地图参照
Point oneMapPoint=(点)GeometryEngine.project(点,世界地图,oneMap);
//创建红色钻石图形
grahpicslayer.addGraphic(新图形(oneMapPoint,新SimpleMarkerSymbol(Color.RED,20,STYLE.CIRCLE));
//显示红色菱形图形
mMapView.addLayer(grahpicslayer);
//将地图缩放到该位置
mMapView.zoomToResolution(oneMapPoint,0);
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
System.out.println(“错误”);
}
}

您只调用了一次
addGraphic
,因此您当然只能得到一个图形

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