AndroidStudido配置:
https://developers.arcgis.com/labs/android/create-a-starter-app/
一些简单的功能实现:
https://developers.arcgis.com/labs/?product=android&topic=any
图片.png
拾取坐标:
https://developers.arcgis.com/android/latest/java/sample-code/format-coordinates/
图片.png
只抽出拾取坐标点的代码
public class MainActivity extends AppCompatActivity {
private MapView mMapView;
// Graphic indicating coordinate location in the map
private Graphic coordinateLocation;
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = findViewById(R.id.tv);
mMapView = findViewById(R.id.mapView);
ArcGISMap map = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 34.056295, -117.195800, 16);
mMapView.setMap(map);
Point initialPoint = new Point(0,0, SpatialReferences.getWgs84());
coordinateLocation = new Graphic(initialPoint,
new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CROSS, Color.RED, 20f));
mMapView.getGraphicsOverlays().add(new GraphicsOverlay());
mMapView.getGraphicsOverlays().get(0).getGraphics().add(coordinateLocation);
toCoordinateNotationFromPoint(initialPoint);
mMapView.setOnTouchListener(new ShowCoordinatesMapTouchListener(this, mMapView));
}
/**
* A map touch listener that updates formatted coordinates when a user taps on a location in the associated MapView.
*/
private class ShowCoordinatesMapTouchListener extends DefaultMapViewOnTouchListener {
public ShowCoordinatesMapTouchListener(Context context, MapView mapView) {
super(context, mapView);
}
/**
* Overrides the onSingleTapConfirmed gesture on the MapView, showing formatted coordinates of the tapped location.
* @param e the motion event
* @return true if the listener has consumed the event; false otherwise
*/
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// convert the screen location where user tapped into a map point
Point tapPoint = mMapView.screenToLocation(new android.graphics.Point((int) e.getX(), (int) e.getY()));
toCoordinateNotationFromPoint(tapPoint);
return true;
}
}
/**
* Uses CoordinateFormatter to update the UI with coordinate notation strings based on the given Point.
* @param newLocation Point to convert to coordinate notations
*/
private void toCoordinateNotationFromPoint(Point newLocation) {
if ((newLocation != null) && (! newLocation.isEmpty())) {
coordinateLocation.setGeometry(newLocation);
try {
// use CoordinateFormatter to convert to Latitude Longitude, formatted as Decimal Degrees
// mLatLongDDValue.setText(CoordinateFormatter.toLatitudeLongitude(newLocation,
// CoordinateFormatter.LatitudeLongitudeFormat.DECIMAL_DEGREES, 4));
tv.setText(CoordinateFormatter.toLatitudeLongitude(newLocation,
CoordinateFormatter.LatitudeLongitudeFormat.DECIMAL_DEGREES, 8));//8表示精确到经纬度小数点后面8位
// use CoordinateFormatter to convert to Latitude Longitude, formatted as Degrees, Minutes, Seconds
/* mLatLongDMSValue.setText(CoordinateFormatter.toLatitudeLongitude(newLocation,
CoordinateFormatter.LatitudeLongitudeFormat.DEGREES_MINUTES_SECONDS, 1));
// use CoordinateFormatter to convert to Universal Transverse Mercator, using latitudinal bands indicator
mUtmValue.setText(CoordinateFormatter.toUtm(newLocation,
CoordinateFormatter.UtmConversionMode.LATITUDE_BAND_INDICATORS, true));
// use CoordinateFormatter to convert to United States National Grid (USNG)
mUSNGValue.setText(CoordinateFormatter.toUsng(newLocation, 4, true));*/
}
catch (ArcGISRuntimeException convertException) {
/* String message = String.format("%s Point at '%s'\n%s", getString(R.string.failed_convert),
newLocation.toString(), convertException.getMessage());
Snackbar.make(mMapView, message, Snackbar.LENGTH_SHORT).show();*/
}
}
}
@Override
protected void onPause(){
mMapView.pause();
super.onPause();
}
@Override
protected void onResume(){
super.onResume();
mMapView.resume();
}
@Override
protected void onDestroy() {
super.onDestroy();
mMapView.dispose();
}
}
图片.png
apk示例下载地址:
https://arcgisruntime.maps.arcgis.com/home/item.html?id=6a214d1f4a374a9a873891707c0411ec
github代码地址:
https://github.com/Esri/arcgis-runtime-samples-android
图片.png
ArcGisTool 包括测量工具控件及测量接口,放大缩小控件及放大缩小接口,地图旋转控件及地图旋转接口:
https://github.com/roomanl/ArcgisTool
apk示例的一些截图:
图片.png
图片.png
图片.png
ps:基本所有的操作示例apk中都已实现
END