嗨,
我想在地图上放置多个图钉。目前,我在地图上显示了一个图钉。我尝试编写多个位置名称,但它只加载一个位置.. 这是我的代码。
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");
}
}