arcgis android 图上记录gps轨迹

时间:2024-05-21 17:35:08

原文  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();
}
}
}); } }