且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

arcgis android 图上记录gps轨迹

更新时间:2022-05-12 00:06:20

原文  arcgis android 图上记录gps轨迹

arcgis android 图上记录gps轨迹
public class MainActivity extends Activity {

    MapView mMapView;
    LocationDisplayManager lDisplayManager = null;
    GraphicsLayer gpsGraphicsLayer;
    Polyline mPolyline;
    int pointCount = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // after the content of this activity is set
        // the map can be accessed from the layout
        mMapView = (MapView) findViewById(R.id.map);
        ArcGISTiledMapServiceLayer tile = new ArcGISTiledMapServiceLayer("http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity_Mobile/MapServer");
        mMapView.addLayer(tile);
        gpsGraphicsLayer = new GraphicsLayer();
        mMapView.addLayer(gpsGraphicsLayer);
        mPolyline = new Polyline();
        mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {
            @Override
            public void onStatusChanged(Object source, STATUS status) {
                if (source == mMapView && status == STATUS.INITIALIZED) {
                    lDisplayManager = mMapView.getLocationDisplayManager();//获取LocationDisplayManager
                    lDisplayManager.setAutoPanMode(LocationDisplayManager.AutoPanMode.OFF);
                    lDisplayManager.setShowLocation(false);//不显示当前位置,坐标系不一致坐标偏移严重
                    lDisplayManager.setShowPings(false);
                    lDisplayManager.setAccuracyCircleOn(false);
                    lDisplayManager.setAllowNetworkLocation(true);
                    lDisplayManager.setLocationListener(new LocationListener() {
                        @Override
                        public void onLocationChanged(Location loc) {
                            //火星坐标转换
                            double[] gcj = CoordinateConvert.wgs2GCJ(loc.getLatitude(), loc.getLongitude());

                            Point wgspoint = new Point(gcj[1], gcj[0]);
                            Point p = (Point) GeometryEngine.project(wgspoint,
                                    SpatialReference.create(SpatialReference.WKID_WGS84),
                                    mMapView.getSpatialReference());
                            SimpleMarkerSymbol ptSym = new SimpleMarkerSymbol(Color.BLUE, 15,
                                    SimpleMarkerSymbol.STYLE.CIRCLE);
                            Graphic graphic = new Graphic(p, ptSym, null);
                            if (pointCount == 0) {
                                mPolyline.startPath(p.getX(), p.getY());
                                mMapView.zoomTo(p, 17);
                            } else {
                                mPolyline.lineTo(p.getX(), p.getY());//点画线
                                mMapView.centerAt(p, true);
                            }
                            gpsGraphicsLayer.removeAll();
                            SimpleLineSymbol lineSym = new SimpleLineSymbol(Color.RED, 10);
                            Graphic g = new Graphic(mPolyline, lineSym);
                            gpsGraphicsLayer.addGraphic(g);
                            pointCount++;

                            gpsGraphicsLayer.addGraphic(graphic);
                        }

                        @Override
                        public void onProviderDisabled(String arg0) {
                        }

                        @Override
                        public void onProviderEnabled(String arg0) {
                        }

                        @Override
                        public void onStatusChanged(String arg0, int arg1,
                                                    Bundle arg2) {

                        }
                    });  // Actionlistener

                    lDisplayManager.start();
                }
            }
        });


    }

}
arcgis android 图上记录gps轨迹

 

没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的***、好奇、充满创造力的想法被现实的框架所束缚,让创造力***成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。



    本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/6243776.html,如需转载请自行联系原作者