我们知道某个Geometry的坐标,但不知道具体的位置,该如何使地图快速定位呢?这时需要用到MapView.setExtent方法,来看下这个方法的介绍:Zooms the map to the given geometry so that geometry fits within the bounds of the map.大体的意思即缩小地图定位到Geometry。上代码:
public class MainActivity extends Activity { private MapView mapView; private GraphicsLayer graphicsLayer; private static final String TILED_WORLD_STREETS_URL = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mapView = (MapView) findViewById(R.id.map_view); mapView.addLayer(new ArcGISTiledMapServiceLayer(TILED_WORLD_STREETS_URL)); findViewById(R.id.location).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { //快速定位到线 Polyline polyline = new Polyline(); polyline.startPath(new Point(110, 23)); polyline.lineTo(new Point(115, 25)); //由于加载的地图是墨卡托坐标,这里需要转坐标 Polyline polyline2 = (Polyline) GeometryEngine.project(polyline, SpatialReference.create(SpatialReference.WKID_WGS84), SpatialReference .create(SpatialReference.WKID_WGS84_WEB_MERCATOR)); mapView.setExtent(polyline2); } }); initLayer(); } /** * 添加一条线 */ private void initLayer() { graphicsLayer = new GraphicsLayer(); mapView.addLayer(graphicsLayer); Polyline polyline = new Polyline(); polyline.startPath(new Point(110, 23)); polyline.lineTo(new Point(115, 25)); //由于加载的地图是墨卡托坐标,这里需要转坐标 Polyline polyline2 = (Polyline) GeometryEngine.project(polyline, SpatialReference.create(SpatialReference.WKID_WGS84), SpatialReference .create(SpatialReference.WKID_WGS84_WEB_MERCATOR)); graphicsLayer.addGraphic(new Graphic(polyline2, new SimpleLineSymbol( Color.RED, 3, SimpleLineSymbol.STYLE.SOLID))); } }
没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的*、好奇、充满创造力的想法被现实的框架所束缚,让创造力*成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。
本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/7751971.html,如需转载请自行联系原作者