你的位置:首页 > 操作系统

[操作系统]Arcgis for android 离线查询


 

参考.. 官方API demo 。。。 各种资料

以及。。

 

[html] view plain copy 


  1. ArcGIS for Android示例解析之高亮要素-----HighlightFeatures  
  2. ttp://blog.csdn.net/wozaifeiyang0/article/details/7323606  



 

 

 

[html] view plain copy 


  1. arcgis android 中 Geodatabase geodata = new Geodatabase(filepath);得到geodata为空  
  2.   
  3. http://zhidao.baidu.com/link?url=iH5IDhbjIKOrZE3WffmhHwJ2ZqFF8AzU8tir8qvSl_BP5AUIHiGSc3aKbqZ7MWVHS1_8Umey4tgNcm9fEm3eVX0pN5DMnhe2_Z7FoGa2ppe&qq-pf-to=pcqq.group  

 

[html] view plain copy 


  1. ArcGIS for Android示例解析之FeatureLayer服务-----SelectFeatures  
  2. http://bbs.hiapk.com/thread-3940420-1-1.html  


过程:

通过FeatureLayer我们可以很快的查询出所选的要素,并进行渲染。下面我们梳理一下选择查询的步骤:

1、              FeatureLayer图层对象所需的参数的设置,如:自身的url设置,Options对象设置,以及选择的要素渲染的样式设置等。
2、              定义一个Query对象,并且给其设置所需的值,如:设置查询条件、是否返回几何对象、输入的空间参考、空间要素以及查询的空间关系。
3、              执行FeatureLayer对象的selectFeatures()方法。
 4 、Graphic graphic = new Graphic(feature.getGeometry(),
                               sfs);
                        // add graphic to layer
                        mGraphicsLayer.addGraphic(graphic);
 
详细:先
1.GraphicsLayer mGraphicsLayer = new GraphicsLayer();  //类似于画布
final String tpkPath = "/Arcgis/hello.tpk";
    public static final String GEO_FILENAME="/Arcgis/hello/data/z01.geodatabase";//数据存放地址
2. onCreate里面加 mMapView.addLayer(mGraphicsLayer); 
3.class TouchListener extends MapOnTouchListener {
长按清除所有画布的要素
[html] view plain copy 


  1. public void onLongPress(MotionEvent point) {  
  2.       // Our long press will clear the screen  
  3.       mStops.clearFeatures();  
  4.       mGraphicsLayer.removeAll();  
  5.       mMapView.getCallout().hide();  
  6.     }  

[html] view plain copy 


  1. public boolean onSingleTap(MotionEvent point) {  
  2.         Point mapPoint = mMapView.toMapPoint(point.getX(), point.getY());  
  3.         Log.i("zjx",""+mapPoint.getX()/1000+",,,"+(mapPoint.getY()/1000+1));  
  4.         Graphic graphic = new Graphic(mapPoint, new SimpleMarkerSymbol(Color.BLUE, 10, STYLE.DIAMOND));  
  5.         mGraphicsLayer.addGraphic(graphic);}  

单击得到相对地图的位置

双击。。这里我订死了查询条件,显示要素
Geodatabase geodatabase =null;
        try {
            geodatabase =new Geodatabase(filename);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        List<GeodatabaseFeatureTable> table = geodatabase
      .getGeodatabaseTables();
        Log.i("zjx","list:"+table);
        GeodatabaseFeatureTable mytable=geodatabase.getGeodatabaseFeatureTableByLayerId(0);

得到数据库 以及第一个数据表
[html] view plain copy 


  1.  FeatureLayer  featureLayer = new FeatureLayer(mytable);  
  2.         QueryParameters qParameters = new QueryParameters();  
  3.         String whereClause = "name='z5'";  
  4. //        SpatialReference sr = SpatialReference.create(102100);  
  5.         qParameters.setGeometry(mMapView.getExtent());  
  6. //        qParameters.setOutSpatialReference(sr);  
  7.         qParameters.setReturnGeometry(true);  
  8.         qParameters.setWhere(whereClause);  
  9.         CallbackListener<FeatureResult> callback=new CallbackListener<FeatureResult>(){  
  10.             public void onError(Throwable e) {  
  11.                 e.printStackTrace();  
  12.             }  
  13.   
  14.             public void onCallback(FeatureResult featureIterator) {  
  15.                 //...  
  16.                 Log.i("zjx","featureIterator.featureCount():"+featureIterator.featureCount());  
  17.                 Log.i("zjx","featureIterator.getDisplayFieldName()"+featureIterator.getDisplayFieldName());  
  18.                 Log.i("zjx","i m callback");  
  19.             }  
  20.   
  21.   
  22.         };  
  23.         Log.i("zjx","sb:"+featureLayer.selectFeatures(qParameters, FeatureLayer.SelectionMode.NEW,callback));  
  24. //        featureLayer.getU  
  25.         Future<FeatureResult> resultFuture=featureLayer.selectFeatures(qParameters, FeatureLayer.SelectionMode.NEW,callback);  
  26.         Log.i("zjx","resultFuture:"+ resultFuture);  
  27.         try{  
  28.             FeatureResult results = resultFuture.get();//最关键  得到结果  
  29.             Log.i("zjx","feature.featureCount():"+results.featureCount());//得到结果的数量  
  30.             Log.i("zjx","feature.getDisplayFieldName():"+results.getDisplayFieldName());  
  31.             if (results != null) {  
  32.                 Log.i("zjx","results no null");  
  33.                 int size = (int) results.featureCount();  
  34.                 int i = 0;  
  35.                 for (Object element : results) {//得到每个要素  
  36.                     Log.i("zjx","the element:"+element);  
  37.                     if (element instanceof Feature) {  
  38.                         Log.i("zjx","element");  
  39.                         Feature feature = (Feature) element;  
  40.                         Log.i("zjx","Feature feature = (Feature) element;:"+element);  
  41.                         // turn feature into graphic  
  42.                         Random r = new Random();  
  43.                         int color = Color.rgb(r.nextInt(255), r.nextInt(255), r.nextInt(255));  
  44.                         SimpleFillSymbol sfs = new SimpleFillSymbol(color);  
  45.                         sfs.setAlpha(75);  
  46.                         Graphic graphic = new Graphic(feature.getGeometry(),  
  47.                                sfs);  
  48.                         // add graphic to layer  
  49.                         mGraphicsLayer.addGraphic(graphic);//显示要素  
  50.                     }  
  51.                     i++;  
  52.                 }  
  53.                 // update message with results  
  54.   
  55.   
  56.             }  

设置查询条件 高亮样式



 
 
完整:
[java] view plain copy 


  1. package com.esri.arcgis.android.samples.offlineroutingandgeocoding;  
  2.   
  3. import java.io.FileNotFoundException;  
  4. import java.util.ArrayList;  
  5. import java.util.List;  
  6. import java.util.Map;  
  7. import java.util.Random;  
  8. import java.util.concurrent.Future;  
  9.   
  10. import android.app.Activity;  
  11. import android.content.Context;  
  12. import android.graphics.Color;  
  13. import android.os.Bundle;  
  14. import android.os.Environment;  
  15. import android.util.Log;  
  16. import android.view.LayoutInflater;  
  17. import android.view.Menu;  
  18. import android.view.MotionEvent;  
  19. import android.view.View;  
  20. import android.widget.AdapterView;  
  21. import android.widget.AdapterView.OnItemSelectedListener;  
  22. import android.widget.ArrayAdapter;  
  23. import android.widget.Spinner;  
  24. import android.widget.TextView;  
  25. import android.widget.Toast;  
  26.   
  27. import com.esri.android.map.FeatureLayer;  
  28. import com.esri.android.map.GraphicsLayer;  
  29. import com.esri.android.map.GraphicsLayer.RenderingMode;  
  30. import com.esri.android.map.MapOnTouchListener;  
  31. import com.esri.android.map.MapView;  
  32. import com.esri.android.map.TiledLayer;  
  33. import com.esri.android.map.ags.ArcGISLocalTiledLayer;  
  34. import com.esri.core.geodatabase.Geodatabase;  
  35. import com.esri.core.geodatabase.GeodatabaseFeature;  
  36. import com.esri.core.geodatabase.GeodatabaseFeatureTable;  
  37. import com.esri.core.geometry.Geometry;  
  38. import com.esri.core.geometry.Point;  
  39. import com.esri.core.geometry.SpatialReference;  
  40. import com.esri.core.map.CallbackListener;  
  41. import com.esri.core.map.Feature;  
  42. import com.esri.core.map.FeatureResult;  
  43. import com.esri.core.map.FeatureSet;  
  44. import com.esri.core.map.Graphic;  
  45. import com.esri.core.symbol.SimpleFillSymbol;  
  46. import com.esri.core.symbol.SimpleLineSymbol;  
  47. import com.esri.core.symbol.SimpleMarkerSymbol;  
  48. import com.esri.core.symbol.SimpleMarkerSymbol.STYLE;  
  49. import com.esri.core.tasks.geocode.Locator;  
  50. import com.esri.core.tasks.geocode.LocatorReverseGeocodeResult;  
  51. import com.esri.core.tasks.na.NAFeaturesAsFeature;  
  52. import com.esri.core.tasks.na.Route;  
  53. import com.esri.core.tasks.na.RouteDirection;  
  54. import com.esri.core.tasks.na.RouteParameters;  
  55. import com.esri.core.tasks.na.RouteResult;  
  56. import com.esri.core.tasks.na.RouteTask;  
  57. import com.esri.core.tasks.na.StopGraphic;  
  58. import com.esri.core.tasks.query.QueryParameters;  
  59.   
  60. public class RoutingAndGeocoding extends Activity {  
  61.   
  62.   // Define ArcGIS Elements  
  63.   MapView mMapView;  
  64.   final String extern = Environment.getExternalStorageDirectory().getPath();  
  65. //  final String tpkPath = "/ArcGIS/samples/OfflineRouting/SanDiego.tpk";  
  66. final String tpkPath = "/Arcgis/hello.tpk";  
  67.     public static final String GEO_FILENAME="/Arcgis/hello/data/z01.geodatabase";  
  68.   TiledLayer mTileLayer = new ArcGISLocalTiledLayer(extern + tpkPath);  
  69.   GraphicsLayer mGraphicsLayer = new GraphicsLayer();  
  70.     String filename=extern+GEO_FILENAME;  
  71.   RouteTask mRouteTask = null;  
  72.   NAFeaturesAsFeature mStops = new NAFeaturesAsFeature();  
  73.   
  74.   Locator mLocator = null;  
  75.   View mCallout = null;  
  76.   Spinner dSpinner;  
  77.   
  78.   @Override  
  79.   protected void onCreate(Bundle savedInstanceState) {  
  80.     super.onCreate(savedInstanceState);  
  81.     setContentView(R.layout.activity_routing_and_geocoding);  
  82.       
  83.     // Find the directions spinner  
  84.     dSpinner = (Spinner) findViewById(R.id.directionsSpinner);  
  85.     dSpinner.setEnabled(false);  
  86.   
  87.     // Retrieve the map and initial extent from 
  88.     mMapView = (MapView) findViewById(R.id.map);  
  89.   
  90.     // Set the tiled map service layer and add a graphics layer  
  91.     mMapView.addLayer(mTileLayer);  
  92.     mMapView.addLayer(mGraphicsLayer);  
  93.   
  94.     // Initialize the RouteTask and Locator with the local data  
  95.     initializeRoutingAndGeocoding();  
  96.     mMapView.setOnTouchListener(new TouchListener(RoutingAndGeocoding.this, mMapView));  
  97.   //    Point mapPoint = null;  
  98.   
  99. //      mapPoint.setXY(0.1942*1928,(0.6842-1)*1928);  
  100. //      Log.i("zjx",""+mapPoint);  
  101. //      Graphic graphic = new Graphic(mapPoint, new SimpleMarkerSymbol(Color.BLUE, 10, STYLE.DIAMOND));  
  102. //      mGraphicsLayer.addGraphic(graphic);  
  103.   }  
  104.   
  105.   private void initializeRoutingAndGeocoding() {  
  106.   
  107.     // We will spin off the initialization in a new thread  
  108.     new Thread(new Runnable() {  
  109.   
  110.       @Override  
  111.       public void run() {  
  112.         // Get the external directory  
  113. //        String locatorPath = "/ArcGIS/samples/OfflineRouting/Geocoding/SanDiego_StreetAddress.loc";  
  114. //        String networkPath = "/ArcGIS/samples/OfflineRouting/Routing/RuntimeSanDiego.geodatabase";  
  115.             String locatorPath = "/Arcgis/hello/data/z01.loc";  
  116.             String networkPath = "/Arcgis/hello/data/z01.geodatabase";  
  117.             String networkName = "Streets_ND";  
  118.   
  119.         // Attempt to load the local geocoding and routing data  
  120.         try {  
  121.           mLocator = Locator.createLocalLocator(extern + locatorPath);  
  122.           mRouteTask = RouteTask.createLocalRouteTask(extern + networkPath, networkName);  
  123.         } catch (Exception e) {  
  124.           popToast("Error while initializing :" + e.getMessage(), true);  
  125.           e.printStackTrace();  
  126.         }  
  127.       }  
  128.     }).start();  
  129.   }  
  130.   
  131.   class TouchListener extends MapOnTouchListener {  
  132.   
  133.     private int routeHandle = -1;  
  134.   
  135.     @Override  
  136.     public void onLongPress(MotionEvent point) {  
  137.       // Our long press will clear the screen  
  138.       mStops.clearFeatures();  
  139.       mGraphicsLayer.removeAll();  
  140.       mMapView.getCallout().hide();  
  141.     }  
  142.   
  143.     @Override  
  144.     public boolean onSingleTap(MotionEvent point) {  
  145.         Point mapPoint = mMapView.toMapPoint(point.getX(), point.getY());  
  146.         Log.i("zjx",""+mapPoint.getX()/1000+",,,"+(mapPoint.getY()/1000+1));  
  147.         Graphic graphic = new Graphic(mapPoint, new SimpleMarkerSymbol(Color.BLUE, 10, STYLE.DIAMOND));  
  148.         mGraphicsLayer.addGraphic(graphic);  
  149.       if (mLocator == null) {  
  150.             popToast("Locator uninitialized", true);  
  151.             return super.onSingleTap(point);  
  152.         }  
  153.   
  154.       String stopAddress = "";  
  155.       try {  
  156.         // Attempt to reverse geocode the point.  
  157.         // Our input and output spatial reference will  
  158.         // be the same as the map.  
  159.         SpatialReference mapRef = mMapView.getSpatialReference();  
  160.         LocatorReverseGeocodeResult result = mLocator.reverseGeocode(mapPoint, 50, mapRef, mapRef);  
  161.   
  162.         // Construct a nicely formatted address from the results  
  163.         StringBuilder address = new StringBuilder();  
  164.         if (result != null && result.getAddressFields() != null) {  
  165.           Map<String, String> addressFields = result.getAddressFields();  
  166.           address.append(String.format("%s\n%s, %s %s", addressFields.get("Street"), addressFields.get("City"),  
  167.               addressFields.get("State"), addressFields.get("ZIP")));  
  168.         }  
  169.   
  170.         // Show the results of the reverse geocoding in  
  171.         // the map's callout.  
  172.         stopAddress = address.toString();  
  173.         showCallout(stopAddress, mapPoint);  
  174.   
  175.       } catch (Exception e) {  
  176.         Log.v("Reverse Geocode", e.getMessage());  
  177.       }  
  178.   
  179.       // Add the touch event as a stop  
  180.       StopGraphic stop = new StopGraphic(graphic);  
  181.       stop.setName(stopAddress.toString());  
  182.       mStops.addFeature(stop);  
  183.   
  184.       return true;  
  185.     }  
  186.   
  187.     @Override  
  188.     public boolean onDoubleTap(MotionEvent point) {  
  189.         Log.i("zjx","double");  
  190.   
  191.        // String filename=Environment.getExternalStorageDirectory().getAbsolutePath()+GEO_FILENAME;  
  192.         Geodatabase geodatabase =null;  
  193.         try {  
  194.             geodatabase =new Geodatabase(filename);  
  195.         } catch (FileNotFoundException e) {  
  196.             // TODO Auto-generated catch block  
  197.             e.printStackTrace();  
  198.         }  
  199.         List<GeodatabaseFeatureTable> table = geodatabase  
  200.       .getGeodatabaseTables();  
  201.         Log.i("zjx","list:"+table);  
  202.         GeodatabaseFeatureTable mytable=geodatabase.getGeodatabaseFeatureTableByLayerId(0);  
  203.         FeatureLayer  featureLayer = new FeatureLayer(mytable);  
  204.         QueryParameters qParameters = new QueryParameters();  
  205.         String whereClause = "name='z5'";  
  206. //        SpatialReference sr = SpatialReference.create(102100);  
  207.         qParameters.setGeometry(mMapView.getExtent());  
  208. //        qParameters.setOutSpatialReference(sr);  
  209.         qParameters.setReturnGeometry(true);  
  210.         qParameters.setWhere(whereClause);  
  211.         CallbackListener<FeatureResult> callback=new CallbackListener<FeatureResult>(){  
  212.             public void onError(Throwable e) {  
  213.                 e.printStackTrace();  
  214.             }  
  215.   
  216.             public void onCallback(FeatureResult featureIterator) {  
  217.                 //...  
  218.                 Log.i("zjx","featureIterator.featureCount():"+featureIterator.featureCount());  
  219.                 Log.i("zjx","featureIterator.getDisplayFieldName()"+featureIterator.getDisplayFieldName());  
  220.                 Log.i("zjx","i m callback");  
  221.             }  
  222.   
  223.   
  224.         };  
  225.         Log.i("zjx","sb:"+featureLayer.selectFeatures(qParameters, FeatureLayer.SelectionMode.NEW,callback));  
  226. //        featureLayer.getU  
  227.         Future<FeatureResult> resultFuture=featureLayer.selectFeatures(qParameters, FeatureLayer.SelectionMode.NEW,callback);  
  228.         Log.i("zjx","resultFuture:"+ resultFuture);  
  229.         try{  
  230.             FeatureResult results = resultFuture.get();  
  231.             Log.i("zjx","feature.featureCount():"+results.featureCount());  
  232.             Log.i("zjx","feature.getDisplayFieldName():"+results.getDisplayFieldName());  
  233.             if (results != null) {  
  234.                 Log.i("zjx","results no null");  
  235.                 int size = (int) results.featureCount();  
  236.                 int i = 0;  
  237.                 for (Object element : results) {  
  238.                     Log.i("zjx","the element:"+element);  
  239.                     if (element instanceof Feature) {  
  240.                         Log.i("zjx","element");  
  241.                         Feature feature = (Feature) element;  
  242.                         Log.i("zjx","Feature feature = (Feature) element;:"+element);  
  243.                         // turn feature into graphic  
  244.                         Random r = new Random();  
  245.                         int color = Color.rgb(r.nextInt(255), r.nextInt(255), r.nextInt(255));  
  246.                         SimpleFillSymbol sfs = new SimpleFillSymbol(color);  
  247.                         sfs.setAlpha(75);  
  248.                         Graphic graphic = new Graphic(feature.getGeometry(),  
  249.                                sfs);  
  250.                         // add graphic to layer  
  251.                         mGraphicsLayer.addGraphic(graphic);  
  252.                     }  
  253.                     i++;  
  254.                 }  
  255.                 // update message with results  
  256.   
  257.   
  258.             }  
  259.   
  260.   
  261.         }  
  262.        catch (Exception e){  
  263.            Log.i("zjx","e:"+e);  
  264.        }  
  265.   
  266. //        Log.i("zjx","featureLayer2:"+featureLayer);  
  267. //        mMapView.addLayer(featureLayer);  
  268. //        QueryParameters query = new QueryParameters();  
  269. ////        query.setWhere("*");  
  270. //  
  271. //        query.setOutFields(new String[]{"*"});  
  272. //        Log.i("zjx","query:"+query.toString());  
  273. //  
  274.   
  275. //        Future resultFuture = mytable.queryFeatures(query, callback);  
  276. //        try{  
  277. //            Log.i("zjx","resultFuture:"+resultFuture.get().toString());  
  278. //             Object result = resultFuture.get();  
  279. //                Feature feature = (Feature) result;  
  280. //                Map attrs = feature.getAttributes();  
  281. //                Log.i("zjx","feature:"+feature);  
  282. //            Log.i("zjx","attrs:"+attrs);  
  283. //        }  
  284. //        catch(Exception e){  
  285. //  
  286. //            Log.i("zjx","error:"+e);  
  287. //        }  
  288.   
  289. //        Future resultFuture = gdbFeatureTable.queryFeatures(query, new CallbackListener() {  
  290. //  
  291. //            public void onError(Throwable e) {  
  292. //                e.printStackTrace();  
  293. //            }  
  294. //  
  295. //            public void onCallback(FeatureResult featureIterator) {  
  296. //             //   ...  
  297. //            }  
  298. //        });  
  299. //  
  300. //        for (Object result : resultFuture.get()) {  
  301. //            Feature feature = (Feature) result;  
  302. //            // Map attrs = feature.getAttributes();  
  303. //        }  
  304.       // Return default behavior if we did not initialize properly.  
  305. //      if (mRouteTask == null) {  
  306. //        popToast("RouteTask uninitialized.", true);  
  307. //        return super.onDoubleTap(point);  
  308. //      }  
  309. //  
  310. //      try {  
  311. //  
  312. //        // Set the correct input spatial reference on the stops and the  
  313. //        // desired output spatial reference on the RouteParameters object.  
  314. //        SpatialReference mapRef = mMapView.getSpatialReference();  
  315. //        RouteParameters params = mRouteTask.retrieveDefaultRouteTaskParameters();  
  316. //        params.setOutSpatialReference(mapRef);  
  317. //        mStops.setSpatialReference(mapRef);  
  318. //  
  319. //        // Set the stops and since we want driving directions,  
  320. //        // returnDirections==true  
  321. //        params.setStops(mStops);  
  322. //        params.setReturnDirections(true);  
  323. //  
  324. //        // Perform the solve  
  325. //        RouteResult results = mRouteTask.solve(params);  
  326. //  
  327. //        // Grab the results; for offline routing, there will only be one  
  328. //        // result returned on the output.  
  329. //        Route result = results.getRoutes().get(0);  
  330. //  
  331. //        // Remove any previous route Graphics  
  332. //        if (routeHandle != -1)  
  333. //          mGraphicsLayer.removeGraphic(routeHandle);  
  334. //  
  335. //        // Add the route shape to the graphics layer  
  336. //        Geometry geom = result.getRouteGraphic().getGeometry();  
  337. //        routeHandle = mGraphicsLayer.addGraphic(new Graphic(geom, new SimpleLineSymbol(0x99990055, 5)));  
  338. //        mMapView.getCallout().hide();  
  339. //  
  340. //        // Get the list of directions from the result  
  341. //        List<RouteDirection> directions = result.getRoutingDirections();  
  342. //  
  343. //        // enable spinner to receive directions  
  344. //        dSpinner.setEnabled(true);  
  345. //  
  346. //        // Iterate through all of the individual directions items and  
  347. //        // create a nicely formatted string for each.  
  348. //        List<String> formattedDirections = new ArrayList<String>();  
  349. //        for (int i = 0; i < directions.size(); i++) {  
  350. //          RouteDirection direction = directions.get(i);  
  351. //          formattedDirections.add(String.format("%s\nGo %.2f %s For %.2f Minutes", direction.getText(),  
  352. //              direction.getLength(), params.getDirectionsLengthUnit().name(), direction.getMinutes()));  
  353. //        }  
  354. //  
  355. //        // Add a summary String  
  356. //        formattedDirections.add(0, String.format("Total time: %.2f Mintues", result.getTotalMinutes()));  
  357. //  
  358. //        // Create a simple array adapter to visualize the directions in  
  359. //        // the Spinner  
  360. //        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),  
  361. //            android.R.layout.simple_spinner_item, formattedDirections);  
  362. //        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);  
  363. //        dSpinner.setAdapter(adapter);  
  364. //  
  365. //        // Add a custom OnItemSelectedListener to the spinner to allow  
  366. //        // panning to each directions item.  
  367. //        dSpinner.setOnItemSelectedListener(new DirectionsItemListener(directions));  
  368. //  
  369. //      } catch (Exception e) {  
  370. //        popToast("Solve Failed: " + e.getMessage(), true);  
  371. //        e.printStackTrace();  
  372. //      }  
  373.       return true;  
  374.     }  
  375.   
  376.     public TouchListener(Context context, MapView view) {  
  377.       super(context, view);  
  378.     }  
  379.   }  
  380.   
  381.   class DirectionsItemListener implements OnItemSelectedListener {  
  382.   
  383.     private List<RouteDirection> mDirections;  
  384.   
  385.     public DirectionsItemListener(List<RouteDirection> directions) {  
  386.       mDirections = directions;  
  387.     }  
  388.   
  389.     @Override  
  390.     public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {  
  391.       // We have to account for the added summary String  
  392.       if (mDirections != null && pos > 0 && pos <= mDirections.size())  
  393.         mMapView.setExtent(mDirections.get(pos - 1).getGeometry());  
  394.     }  
  395.   
  396.     @Override  
  397.     public void onNothingSelected(AdapterView<?> arg0) {  
  398.     }  
  399.   }  
  400.   
  401.   private void showCallout(String text, Point location) {  
  402.   
  403.     // If the callout has never been created, inflate it  
  404.     if (mCallout == null) {  
  405.       LayoutInflater inflater = (LayoutInflater) getApplication().getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
  406.       mCallout = inflater.inflate(R.layout.callout, null);  
  407.     }  
  408.   
  409.     // Show the callout with the given text at the given location  
  410.     ((TextView) mCallout.findViewById(R.id.calloutText)).setText(text);  
  411.     mMapView.getCallout().show(location, mCallout);  
  412.     mMapView.getCallout().setMaxWidth(700);  
  413.   }  
  414.   
  415.   private void popToast(final String message, final boolean show) {  
  416.     // Simple helper method for showing toast on the main thread  
  417.     if (!show)  
  418.       return;  
  419.   
  420.     runOnUiThread(new Runnable() {  
  421.       @Override  
  422.       public void run() {  
  423.         Toast.makeText(RoutingAndGeocoding.this, message, Toast.LENGTH_SHORT).show();  
  424.       }  
  425.     });  
  426.   }  
  427.   
  428.   @Override  
  429.   public boolean onCreateOptionsMenu(Menu menu) {  
  430.     // Inflate the menu; this adds items to the action bar if it is present.  
  431.     getMenuInflater().inflate(R.menu.routing_and_geocoding, menu);  
  432.     return true;  
  433.   }  
  434.   
  435. }  


来自:http://blog.csdn.net/u011644423/article/details/45482577