我想用SDK&ArcGIS for Android开发Android应用程序'。我在那里下载了两个样本:PopupInWebMapForViewing Routing。这就是我的目标:我希望将这两个样本放在一个Projekt或一个.java文件中。
我已经完成了此操作,但该应用程序无法在我的智能手机上运行。它只显示应用已停止。如果我注释掉路由中的所有内容,它将起作用。如果我从路由中取消对层的所有期望,它也将起作用。通过长按地图激活路由。但在这种情况下,应用程序将崩溃。
我不太了解java,但它是大学的一个项目。我希望有人可以帮助我。
非常感谢大家的帮助,对不起我的英语不好。
以下是代码:
public class BAAppActivity extends Activity {
// Progress dialog to show when route is being calculated
ProgressDialog dialog;
// Spatial references used for projecting points
final SpatialReference wm = SpatialReference.create(102100);
final SpatialReference egs = SpatialReference.create(4326);
// Index of the currently selected route segment (-1 = no selection)
int selectedSegmentID = -1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Lade die Basemap von ArcGIS online.
map = new MapView(this, "map", "", "");
setContentView(map);
// Retrieve the map and initial extent from XML layout
map = (MapView) findViewById(R.id.map);
// Add tiled layer to MapView
tileLayer = new ArcGISTiledMapServiceLayer(
"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
map.addLayer(tileLayer);
// Add the route graphic layer (shows the full route)
routeLayer = new GraphicsLayer();
map.addLayer(routeLayer);
// Add the hidden segments layer (for highlighting route segments)
hiddenSegmentsLayer = new GraphicsLayer();
map.addLayer(hiddenSegmentsLayer);
// Make the segmentHider symbol "invisible"
segmentHider.setAlpha(1);
// Get the location service and start reading location. Don't auto-pan
// to center our position
LocationService ls = map.getLocationService();
ls.setLocationListener(new MyLocationListener());
ls.start();
ls.setAutoPan(false);
// Set the directionsLabel with initial instructions.
directionsLabel = (TextView) findViewById(R.id.directionsLabel);
directionsLabel.setText(getString(R.string.route_label));
directionsLabel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (curDirections == null)
return;
Intent i = new Intent(getApplicationContext(),
ShowDirections.class);
i.putStringArrayListExtra("directions", curDirections);
startActivityForResult(i, 1);
}
});
directionsLabel.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
routeLayer.removeAll();
hiddenSegmentsLayer.removeAll();
curRoute = null;
curDirections = null;
directionsLabel.setText(getString(R.string.route_label));
return true;
}
});
// Tippe auf die Karte und öffne ein Popup für das selektierte Feature.
map.setOnSingleTapListener(new OnSingleTapListener() {
private static final long serialVersionUID = 1L;
public void onSingleTap(float x, float y) {
// Get all the graphics within 20 pixels the click
int[] indexes = hiddenSegmentsLayer.getGraphicIDs(x, y, 20);
// Hide the currently selected segment
hiddenSegmentsLayer.updateGraphic(selectedSegmentID,
segmentHider);
if (indexes.length < 1) {
// If no segments were found but there is currently a route,
// zoom to the extent of the full route
if (curRoute != null) {
map.setExtent(curRoute.getEnvelope(), 250);
directionsLabel.setText(routeSummary);
}
return;
}
// Otherwise update our currently selected segment
selectedSegmentID = indexes[0];
Graphic selected = hiddenSegmentsLayer
.getGraphic(selectedSegmentID);
// Highlight it on the map
hiddenSegmentsLayer.updateGraphic(selectedSegmentID,
segmentShower);
String direction = ((String) selected.getAttributeValue("text"));
double time = ((Double) selected.getAttributeValue("time"))
.doubleValue();
double length = ((Double) selected.getAttributeValue("length"))
.doubleValue();
// Update the label with this direction's information
String label = String.format(
"%s%nTime: %.1f minutes, Length: %.1f miles",
direction, time, length);
directionsLabel.setText(label);
// Zoom to the extent of that segment
map.setExtent(selected.getGeometry(), 50);
if (map.isLoaded()) {
// PopupContainer realisieren.
popupContainer = new PopupContainer(map);
int id = popupContainer.hashCode();
popupDialog = null;
// spinner (Auswahl) anzeigen.
if (progressDialog == null || !progressDialog.isShowing())
progressDialog = ProgressDialog.show(map.getContext(), "", "Rufe Informationen ab...");
// Loop durch jeden Layer in der Basemap.
int tolerance = 20;
Envelope env = new Envelope(map.toMapPoint(x, y), 20 * map.getResolution(), 20 * map.getResolution());
Layer[] layers = map.getLayers();
count = new AtomicInteger();
for (Layer layer : layers) {
// Wenn der Layer noch nicht geladen wurde oder unsichtbar ist, nichts machen.
if (!layer.isInitialized() || !layer.isVisible())
continue;
if (layer instanceof ArcGISFeatureLayer) {
// Frage den FeatureLayer ab und zeige die Popups.
ArcGISFeatureLayer featureLayer = (ArcGISFeatureLayer) layer;
if (featureLayer.getPopupInfo() != null) {
// Frage den FeatureLayer ab, welcher mit den Popupdefinitionen verknüpft ist.
count.incrementAndGet();
new RunQueryFeatureLayerTask(x, y, tolerance, id).execute(featureLayer);
}
}
else if (layer instanceof ArcGISDynamicMapServiceLayer) {
// Frage den DynamicLayer ab und zeige die Popups.
ArcGISDynamicMapServiceLayer dynamicLayer = (ArcGISDynamicMapServiceLayer) layer;
// Empfange Layerinfos für jeden Sub-Layer des dynamic map service layer.
ArcGISLayerInfo[] layerinfos = dynamicLayer.getAllLayers();
if (layerinfos == null)
continue;
// Loop durch jeden Sub-Layer.
for (ArcGISLayerInfo layerInfo : layerinfos) {
// erhalte PopupInfo für die Sub-Layer.
PopupInfo popupInfo = dynamicLayer.getPopupInfo(layerInfo.getId());
// Überspringe Sub-Layer, welche keine Popup-Definitionen enthalten.
if (popupInfo == null) {
continue;
}
// Überprüfe ob der Sub-Layer sichtbar ist.
ArcGISLayerInfo info = layerInfo;
while (info != null && info.isVisible()) {
info = info.getParentLayer();
}
// Überspringe unsichtbare Sub-Layer.
if (info != null && ! info.isVisible()) {
continue;
};
// Überprüfe ob der Sub-Layer innerhalb des Skalenbereichs ist.
double maxScale = (layerInfo.getMaxScale() != 0) ? layerInfo.getMaxScale():popupInfo.getMaxScale();
double minScale = (layerInfo.getMinScale() != 0) ? layerInfo.getMinScale():popupInfo.getMinScale();
if ((maxScale == 0 || map.getScale() > maxScale) && (minScale == 0 || map.getScale() < minScale)) {
// Frage die Sub-Layer ab, welche mit den Popup-Definitionen verknüpft sind und sichtbar sind und im Skalenbereich liegen.
count.incrementAndGet();
new RunQueryDynamicLayerTask(env, layer, layerInfo.getId(), dynamicLayer.getSpatialReference(), id).execute(dynamicLayer.getUrl() + "/" + layerInfo.getId());
}
}
}
}
}
}
});
map.setOnLongPressListener(new OnLongPressListener() {
private static final long serialVersionUID = 1L;
public void onLongPress(final float x, final float y) {
// Clear the graphics and empty the directions list
routeLayer.removeAll();
hiddenSegmentsLayer.removeAll();
curDirections = new ArrayList<String>();
mResults = null;
// retrieve the user clicked location
final Point loc = map.toMapPoint(x, y);
// Show that the route is calculating
dialog = ProgressDialog.show(BAAppActivity.this, "",
"Calculating route...", true);
// Spawn the request off in a new thread to keep UI responsive
Thread t = new Thread() {
@Override
public void run() {
try {
// Start building up routing parameters
RoutingParameters rp = new RoutingParameters();
NAFeaturesAsFeature rfaf = new NAFeaturesAsFeature();
// Convert point to EGS (decimal degrees)
Point p = (Point) GeometryEngine.project(loc, wm,
egs);
// Create the stop points (start at our location, go
// to pressed location)
StopGraphic point1 = new StopGraphic(mLocation);
StopGraphic point2 = new StopGraphic(p);
rfaf.setFeatures(new Graphic[] { point1, point2 });
rfaf.setCompressedRequest(true);
rp.setStops(rfaf);
// Set the routing service output SR to our map
// service's SR
rp.setOutSpatialReference(wm);
// Create a new routing task pointing to an
// NAService (null credentials -> free service)
RoutingTask rt = new RoutingTask(
"http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_EU/NAServer/Route",
null);
// Solve the route and use the results to update UI
// when received
mResults = rt.solve(rp);
mHandler.post(mUpdateResults);
} catch (Exception e) {
mException = e;
mHandler.post(mUpdateResults);
}
}
};
// Start the operation
t.start();
}
});
}
private void createPopupViews(Graphic[] graphics, final int id) {
if (id != popupContainer.hashCode()) {
if (progressDialog != null && progressDialog.isShowing() && count.intValue() == 0)
progressDialog.dismiss();
return;
}
if (popupDialog == null) {
if (progressDialog != null && progressDialog.isShowing())
progressDialog.dismiss();
// Mache einen Dialog für die popups und zeige ihn.
popupDialog = new PopupDialog(map.getContext(), popupContainer);
popupDialog.show();
}
}
// Frage den Feature Layer durch einen Trefferüberprüfung ab.
private class RunQueryFeatureLayerTask extends AsyncTask<ArcGISFeatureLayer, Void, Graphic[]> {
private int tolerance;
private float x;
private float y;
private ArcGISFeatureLayer featureLayer;
private int id;
public RunQueryFeatureLayerTask(float x, float y, int tolerance, int id) {
super();
this.x = x;
this.y = y;
this.tolerance = tolerance;
this.id = id;
}
@Override
protected Graphic [] doInBackground(ArcGISFeatureLayer...params) {
for (ArcGISFeatureLayer featureLayer : params) {
this.featureLayer = featureLayer;
// Grafik-IDs in der Nähe der Punkte abrufen.
int[] ids = featureLayer.getGraphicIDs(x, y, tolerance);
if (ids != null && ids.length > 0) {
ArrayList<Graphic> graphics = new ArrayList<Graphic>();
for (int id : ids) {
// Grafiken basierend auf den IDs erhalten.
Graphic g = featureLayer.getGraphic(id);
if (g == null)
continue;
graphics.add(g);
}
// Liefert ein Array von Grafiken in der Nähe des Punktes.
return graphics.toArray(new Graphic[0]);
}
}
return null;
}
@Override
protected void onPostExecute(Graphic[] graphics) {
count.decrementAndGet();
if (graphics == null || graphics.length == 0) {
if (progressDialog != null && progressDialog.isShowing() && count.intValue() == 0)
progressDialog.dismiss();
return;
}
for (Graphic gr : graphics) {
Popup popup = featureLayer.createPopup(map, 0, gr);
popupContainer.addPopup(popup);
}
createPopupViews(graphics, id);
}
}
// Frage den Dynamic Map Service Layer mit QueryTask ab.
private class RunQueryDynamicLayerTask extends AsyncTask<String, Void, FeatureSet> {
private Envelope env;
private SpatialReference sr;
private int id;
private Layer layer;
private int subLayerId;
public RunQueryDynamicLayerTask(Envelope env, Layer layer, int subLayerId, SpatialReference sr, int id) {
super();
this.env = env;
this.sr = sr;
this.id = id;
this.layer = layer;
this.subLayerId = subLayerId;
}
@Override
protected FeatureSet doInBackground(String... urls) {
for (String url : urls) {
// Erhalte Grafiken innerhalb der Hülle.
Query query = new Query();
query.setInSpatialReference(sr);
query.setOutSpatialReference(sr);
query.setGeometry(env);
query.setMaxFeatures(10);
query.setOutFields(new String[] { "*" });
QueryTask queryTask = new QueryTask(url);
try {
FeatureSet results = queryTask.execute(query);
return results;
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(final FeatureSet result) {
count.decrementAndGet();
if (result == null) {
if (progressDialog != null && progressDialog.isShowing() && count.intValue() == 0)
progressDialog.dismiss();
return;
}
Graphic[] graphics = result.getGraphics();
if (graphics == null || graphics.length == 0) {
if (progressDialog != null && progressDialog.isShowing() && count.intValue() == 0)
progressDialog.dismiss();
return;
}
// Überprüfen, ob die angeforderte PopupContainer-Id identisch mit dem aktuellen PopupContainer ist.
// Andernfalls verlasse die veralteten Abfragen.
if (id != popupContainer.hashCode()) {
// Spinner verwerfen.
if (progressDialog != null && progressDialog.isShowing() && count.intValue() == 0)
progressDialog.dismiss();
return;
}
PopupInfo popupInfo = layer.getPopupInfo(subLayerId);
if (popupInfo == null) {
// Spinner verwerfen.
if (progressDialog != null && progressDialog.isShowing() && count.intValue() == 0)
progressDialog.dismiss();
return;
}
for (Graphic gr : graphics) {
Popup popup = layer.createPopup(map, subLayerId, gr);
popupContainer.addPopup(popup);
}
createPopupViews(graphics, id);
}
}
// Ein angepasster Vollbild-Dialog.
private class PopupDialog extends Dialog {
private PopupContainer popupContainer;
public PopupDialog(Context context, PopupContainer popupContainer) {
super(context, android.R.style.Theme);
this.popupContainer = popupContainer;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
LinearLayout layout = new LinearLayout(getContext());
layout.addView(popupContainer.getPopupContainerView(), LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
setContentView(layout, params);
}
}
void updateUI() {
dialog.dismiss();
if (mResults == null) {
Toast.makeText(BAAppActivity.this, mException.toString(),
Toast.LENGTH_LONG).show();
return;
}
curRoute = mResults.getRoutes().get(0);
// Symbols for the route and the destination (blue line, checker flag)
SimpleLineSymbol routeSymbol = new SimpleLineSymbol(Color.BLUE, 3);
PictureMarkerSymbol destinationSymbol = new PictureMarkerSymbol(
getResources().getDrawable(R.drawable.flag_finish));
// Add all the route segments with their relevant information to the
// hiddenSegmentsLayer, and add the direction information to the list
// of directions
for (RoutingDirection rd : curRoute.getRoutingDirections()) {
HashMap<String, Object> attribs = new HashMap<String, Object>();
attribs.put("text", rd.getText());
attribs.put("time", Double.valueOf(rd.getTime()));
attribs.put("length", Double.valueOf(rd.getLength()));
curDirections.add(String.format(
"%s%nTime: %.1f minutes, Length: %.1f miles", rd.getText(),
rd.getTime(), rd.getLength()));
hiddenSegmentsLayer.addGraphic(new Graphic(rd.getGeometry(),
segmentHider, attribs, null));
}
// Reset the selected segment
selectedSegmentID = -1;
// Add the full route graphic and destination graphic to the routeLayer
Graphic routeGraphic = new Graphic(curRoute.getRoute().getGeometry(),
routeSymbol);
Graphic endGraphic = new Graphic(
((Polyline) routeGraphic.getGeometry()).getPoint(((Polyline) routeGraphic
.getGeometry()).getPointCount() - 1), destinationSymbol);
routeLayer.addGraphics(new Graphic[] { routeGraphic, endGraphic });
// Get the full route summary and set it as our current label
routeSummary = String.format(
"%s%nTotal time: %.1f minutes, length: %.1f miles",
curRoute.getRouteName(), curRoute.getTotalTime(),
curRoute.getTotalLength());
directionsLabel.setText(routeSummary);
// Zoom to the extent of the entire route with a padding
map.setExtent(curRoute.getEnvelope(), 250);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Response from directions list view
if (requestCode == 1) {
if (resultCode == RESULT_OK) {
String direction = data.getStringExtra("returnedDirection");
if (direction == null)
return;
// Look for the graphic that corresponds to this direction
for (int index : hiddenSegmentsLayer.getGraphicIDs()) {
Graphic g = hiddenSegmentsLayer.getGraphic(index);
if (direction
.contains((String) g.getAttributeValue("text"))) {
// When found, hide the currently selected, show the new
// selection
hiddenSegmentsLayer.updateGraphic(selectedSegmentID,
segmentHider);
hiddenSegmentsLayer.updateGraphic(index, segmentShower);
selectedSegmentID = index;
// Update label with information for that direction
directionsLabel.setText(direction);
// Zoom to the extent of that segment
map.setExtent(
hiddenSegmentsLayer.getGraphic(
selectedSegmentID).getGeometry(), 50);
break;
}
}
}
}
}
private class MyLocationListener implements LocationListener {
public MyLocationListener() {
super();
}
/**
* If location changes, update our current location. If being found for
* the first time, zoom to our current position with a resolution of 20
*/
public void onLocationChanged(Location loc) {
if (loc == null)
return;
boolean zoomToMe = (mLocation == null) ? true : false;
mLocation = new Point(loc.getLongitude(), loc.getLatitude());
if (zoomToMe) {
Point p = (Point) GeometryEngine.project(mLocation, egs, wm);
map.zoomToResolution(p, 20.0);
}
}
}
}
和LogCat:
10-28 14:19:27.586: E/ArcGIS(26937): Can not parse MapView.initExtent from xml
10-28 14:19:27.586: E/ArcGIS(26937): java.text.ParseException: Unparseable number: "-19332033.11," (at offset 9)
10-28 14:19:27.586: E/ArcGIS(26937): at java.text.NumberFormat.parse(NumberFormat.java:545)
10-28 14:19:27.586: E/ArcGIS(26937): at com.esri.android.map.MapView.a(Unknown Source)
10-28 14:19:27.586: E/ArcGIS(26937): at com.esri.android.map.MapView.a(Unknown Source)
10-28 14:19:27.586: E/ArcGIS(26937): at com.esri.android.map.MapView.<init>(Unknown Source)
10-28 14:19:27.586: E/ArcGIS(26937): at java.lang.reflect.Constructor.constructNative(Native Method)
10-28 14:19:27.586: E/ArcGIS(26937): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
10-28 14:19:27.586: E/ArcGIS(26937): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
10-28 14:19:27.586: E/ArcGIS(26937): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
10-28 14:19:27.586: E/ArcGIS(26937): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
10-28 14:19:27.586: E/ArcGIS(26937): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
10-28 14:19:27.586: E/ArcGIS(26937): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
10-28 14:19:27.586: E/ArcGIS(26937): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-28 14:19:27.586: E/ArcGIS(26937): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:318)
10-28 14:19:27.586: E/ArcGIS(26937): at android.app.Activity.setContentView(Activity.java:1901)
10-28 14:19:27.586: E/ArcGIS(26937): at fhffm.wernicke.ba.app.BAAppActivity.onCreate(BAAppActivity.java:111)
10-28 14:19:27.586: E/ArcGIS(26937): at android.app.Activity.performCreate(Activity.java:5047)
10-28 14:19:27.586: E/ArcGIS(26937): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
10-28 14:19:27.586: E/ArcGIS(26937): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
10-28 14:19:27.586: E/ArcGIS(26937): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
10-28 14:19:27.586: E/ArcGIS(26937): at android.app.ActivityThread.access$700(ActivityThread.java:134)
10-28 14:19:27.586: E/ArcGIS(26937): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
10-28 14:19:27.586: E/ArcGIS(26937): at android.os.Handler.dispatchMessage(Handler.java:99)
10-28 14:19:27.586: E/ArcGIS(26937): at android.os.Looper.loop(Looper.java:137)
10-28 14:19:27.586: E/ArcGIS(26937): at android.app.ActivityThread.main(ActivityThread.java:4867)
10-28 14:19:27.586: E/ArcGIS(26937): at java.lang.reflect.Method.invokeNative(Native Method)
10-28 14:19:27.586: E/ArcGIS(26937): at java.lang.reflect.Method.invoke(Method.java:511)
10-28 14:19:27.586: E/ArcGIS(26937): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
10-28 14:19:27.586: E/ArcGIS(26937): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
10-28 14:19:27.586: E/ArcGIS(26937): at dalvik.system.NativeStart.main(Native Method)
10-28 14:19:27.806: E/SensorManager(26937): thread start
10-28 14:19:27.816: E/AndroidRuntime(26937): FATAL EXCEPTION: main
10-28 14:19:27.816: E/AndroidRuntime(26937): java.lang.RuntimeException: Unable to start activity ComponentInfo{fhffm.wernicke.ba.app/fhffm.wernicke.ba.app.BAAppActivity}: java.lang.NullPointerException
10-28 14:19:27.816: E/AndroidRuntime(26937): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2092)
10-28 14:19:27.816: E/AndroidRuntime(26937): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
10-28 14:19:27.816: E/AndroidRuntime(26937): at android.app.ActivityThread.access$700(ActivityThread.java:134)
10-28 14:19:27.816: E/AndroidRuntime(26937): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
10-28 14:19:27.816: E/AndroidRuntime(26937): at android.os.Handler.dispatchMessage(Handler.java:99)
10-28 14:19:27.816: E/AndroidRuntime(26937): at android.os.Looper.loop(Looper.java:137)
10-28 14:19:27.816: E/AndroidRuntime(26937): at android.app.ActivityThread.main(ActivityThread.java:4867)
10-28 14:19:27.816: E/AndroidRuntime(26937): at java.lang.reflect.Method.invokeNative(Native Method)
10-28 14:19:27.816: E/AndroidRuntime(26937): at java.lang.reflect.Method.invoke(Method.java:511)
10-28 14:19:27.816: E/AndroidRuntime(26937): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
10-28 14:19:27.816: E/AndroidRuntime(26937): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
10-28 14:19:27.816: E/AndroidRuntime(26937): at dalvik.system.NativeStart.main(Native Method)
10-28 14:19:27.816: E/AndroidRuntime(26937): Caused by: java.lang.NullPointerException
10-28 14:19:27.816: E/AndroidRuntime(26937): at fhffm.wernicke.ba.app.BAAppActivity.onCreate(BAAppActivity.java:146)
10-28 14:19:27.816: E/AndroidRuntime(26937): at android.app.Activity.performCreate(Activity.java:5047)
10-28 14:19:27.816: E/AndroidRuntime(26937): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
10-28 14:19:27.816: E/AndroidRuntime(26937): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
10-28 14:19:27.816: E/AndroidRuntime(26937): ... 11 more
祝你好运 losaruka
答案 0 :(得分:0)
在Routing示例中,查看res / layout / main.xml。使用此XML声明MapView:
<com.esri.android.map.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
initExtent = "-19332033.11, -3516.27, -1720941.80, 11737211.28">
</com.esri.android.map.MapView>
不幸的是,initExtent的格式不正确。它应该只有空格,而不是逗号:
initExtent = "-19332033.11 -3516.27 -1720941.80 11737211.28">
删除逗号并尝试一下。
答案 1 :(得分:0)
我自己解决了这个问题:
删除此:
map = new MapView(this, "some map", "", "");
setContentView(map);
并添加:
featureLayer = new ArcGISFeatureLayer(
"featureLayer", MODE.ONDEMAND);
map.addLayer(featureLayer);
后:
map = (MapView) findViewById(R.id.map);
tileLayer = new ArcGISTiledMapServiceLayer(
"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
map.addLayer(tileLayer);
但是我遇到了一个新问题:如果我想在功能上进行标签搜索很长时间而且没有任何结果。如果我点击routeoverview应用程序崩溃。我认为它因两个“onSingleTab”方法而崩溃。如何为两个不同的东西制作其中的两个(我用“onSingleTab1”测试了'Routing'...)?在这段代码中也是功能的东西。我认为它不会出现,因为循环搜索图层。但我唯一拥有的是具有功能的featurelayer。我不知道......
map.setOnSingleTapListener(new OnSingleTapListener() {
private static final long serialVersionUID = 1L;
public void onSingleTap(float x, float y) {
if (map.isLoaded()) {
// PopupContainer realisieren.
popupContainer = new PopupContainer(map);
int id = popupContainer.hashCode();
popupDialog = null;
// spinner (Auswahl) anzeigen.
if (progressDialog == null || !progressDialog.isShowing())
progressDialog = ProgressDialog.show(map.getContext(), "", "Rufe Informationen ab...");
// Loop durch jeden Layer in der Basemap.
int tolerance = 20;
Envelope env = new Envelope(map.toMapPoint(x, y), 20 * map.getResolution(), 20 * map.getResolution());
Layer[] layers = map.getLayers();
count = new AtomicInteger();
for (Layer layer : layers) {
// Wenn der Layer noch nicht geladen wurde oder unsichtbar ist, nichts machen.
if (!layer.isInitialized() || !layer.isVisible())
continue;
if (layer instanceof ArcGISFeatureLayer) {
// Frage den FeatureLayer ab und zeige die Popups.
ArcGISFeatureLayer featureLayer = (ArcGISFeatureLayer) layer;
if (featureLayer.getPopupInfo() != null) {
// Frage den FeatureLayer ab, welcher mit den Popupdefinitionen verknüpft ist.
count.incrementAndGet();
new RunQueryFeatureLayerTask(x, y, tolerance, id).execute(featureLayer);
}
}
}
}
}
////////////////////////////// Routing /////////////////////////////
public void onSingleTap1(float x, float y) {
// Get all the graphics within 20 pixels the click
int[] indexes = hiddenSegmentsLayer.getGraphicIDs(x, y, 20);
// Hide the currently selected segment
hiddenSegmentsLayer.updateGraphic(selectedSegmentID,
segmentHider);
if (indexes.length < 1) {
// If no segments were found but there is currently a route,
// zoom to the extent of the full route
if (curRoute != null) {
map.setExtent(curRoute.getEnvelope(), 250);
directionsLabel.setText(routeSummary);
}
return;
}
// Otherwise update our currently selected segment
selectedSegmentID = indexes[0];
Graphic selected = hiddenSegmentsLayer
.getGraphic(selectedSegmentID);
// Highlight it on the map
hiddenSegmentsLayer.updateGraphic(selectedSegmentID,
segmentShower);
String direction = ((String) selected.getAttributeValue("text"));
double time = ((Double) selected.getAttributeValue("time"))
.doubleValue();
double length = ((Double) selected.getAttributeValue("length"))
.doubleValue();
// Update the label with this direction's information
String label = String.format(
"%s%nTime: %.1f minutes, Length: %.1f miles",
direction, time, length);
directionsLabel.setText(label);
// Zoom to the extent of that segment
map.setExtent(selected.getGeometry(), 50);
}
});
祝你好运
losaruka