-1

我正在开发谷歌地图应用程序并使用代码来查找两点之间的路径,这在Android 2.3.3. 但是现在,我正在对其进行测试Android 4.0.3并且它崩溃了。我觉得它需要转换,AsyncTask但我不能这样做。

在我的DirectionClass中,

    public Document getDocument(LatLng start, LatLng end, String mode) {
    String url = "http://maps.googleapis.com/maps/api/directions/xml?" 
            + "origin=" + start.latitude + "," + start.longitude  
            + "&destination=" + end.latitude + "," + end.longitude 
            + "&sensor=false&units=metric&mode=driving";

    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpContext localContext = new BasicHttpContext();
        HttpPost httpPost = new HttpPost(url);
        HttpResponse response = httpClient.execute(httpPost, localContext);
        InputStream in = response.getEntity().getContent();
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(in);
        return doc;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

    public ArrayList<LatLng> getDirection (Document doc) {
    NodeList nl1, nl2, nl3;
    ArrayList<LatLng> listGeopoints = new ArrayList<LatLng>();
    nl1 = doc.getElementsByTagName("step");
    if (nl1.getLength() > 0) {
        for (int i = 0; i < nl1.getLength(); i++) {
            Node node1 = nl1.item(i);
            nl2 = node1.getChildNodes();

            Node locationNode = nl2.item(getNodeIndex(nl2, "start_location"));
            nl3 = locationNode.getChildNodes();
            Node latNode = nl3.item(getNodeIndex(nl3, "lat"));
            double lat = Double.parseDouble(latNode.getTextContent());
            Node lngNode = nl3.item(getNodeIndex(nl3, "lng"));
            double lng = Double.parseDouble(lngNode.getTextContent());
            listGeopoints.add(new LatLng(lat, lng));

            locationNode = nl2.item(getNodeIndex(nl2, "polyline"));
            nl3 = locationNode.getChildNodes();
            latNode = nl3.item(getNodeIndex(nl3, "points"));
            ArrayList<LatLng> arr = decodePoly(latNode.getTextContent());
            for(int j = 0 ; j < arr.size() ; j++) {
                listGeopoints.add(new LatLng(arr.get(j).latitude, arr.get(j).longitude));
            }

            locationNode = nl2.item(getNodeIndex(nl2, "end_location"));
            nl3 = locationNode.getChildNodes();
            latNode = nl3.item(getNodeIndex(nl3, "lat"));
            lat = Double.parseDouble(latNode.getTextContent());
            lngNode = nl3.item(getNodeIndex(nl3, "lng"));
            lng = Double.parseDouble(lngNode.getTextContent());
            listGeopoints.add(new LatLng(lat, lng));
        }
    }

    return listGeopoints;
}

在 MapActivity 我有

Document doc = md.getDocument(fromPosition,toPosition , GMapV2Direction.MODE_DRIVING);
ArrayList<LatLng> directionPoint = md.getDirection(doc);

错误日志

 '/data/data/com.archifiles.pointpakistan/databases/pointpakistan.db' 
    05-17 16:20:45.004: E/SQLiteDatabase(25473):              android.database.sqlite.DatabaseObjectNotClosedException: 
Application did not close the cursor or database object that was opened here
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:2078)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1132)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1089)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1065)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1168)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1161)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:838)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:222)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at com.archifiles.pointpakistan.POIActivity.findandShowPOIsfromCloud(POIActivity.java:490)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at com.archifiles.pointpakistan.POIActivity.onCreate(POIActivity.java:251)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.app.Activity.performCreate(Activity.java:4465)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.os.Looper.loop(Looper.java:137)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at android.app.ActivityThread.main(ActivityThread.java:4512)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at java.lang.reflect.Method.invokeNative(Native Method)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at java.lang.reflect.Method.invoke(Method.java:511)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:984)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
05-17 16:20:45.004: E/SQLiteDatabase(25473):    at dalvik.system.NativeStart.main(Native Method)
05-17 16:20:45.004: E/System(25473): Uncaught exception thrown by finalizer
05-17 16:20:45.020: E/System(25473): java.lang.IllegalStateException: Don't have database lock!
05-17 16:20:45.020: E/System(25473):    at android.database.sqlite.SQLiteDatabase.verifyLockOwner(SQLiteDatabase.java:2236)
05-17 16:20:45.020: E/System(25473):    at android.database.sqlite.SQLiteDatabase$1.entryRemoved(SQLiteDatabase.java:2328)
05-17 16:20:45.020: E/System(25473):    at android.database.sqlite.SQLiteDatabase$1.entryRemoved(SQLiteDatabase.java:2324)
05-17 16:20:45.020: E/System(25473):    at android.util.LruCache.trimToSize(LruCache.java:197)
05-17 16:20:45.020: E/System(25473):    at android.util.LruCache.evictAll(LruCache.java:285)
05-17 16:20:45.020: E/System(25473):    at android.database.sqlite.SQLiteDatabase.deallocCachedSqlStatements(SQLiteDatabase.java:2289)
05-17 16:20:45.020: E/System(25473):    at android.database.sqlite.SQLiteDatabase.closeClosable(SQLiteDatabase.java:1261)
05-17 16:20:45.020: E/System(25473):    at android.database.sqlite.SQLiteDatabase.finalize(SQLiteDatabase.java:2049)
05-17 16:20:45.020: E/System(25473):    at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:185)
05-17 16:20:45.020: E/System(25473):    at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:168)
05-17 16:20:45.020: E/System(25473):    at java.lang.Thread.run(Thread.java:856)
4

1 回答 1

0

你可以尝试这样的事情。它是一种简单的方向替代方法。它只使用手机上的导航应用程序。

Intent intent = new Intent(
                        android.content.Intent.ACTION_VIEW,
                        Uri.parse("http://maps.google.com/maps?saddr="
                                + mLat + ","
                                + mLong
                                + "&daddr=10.773615,76.655345"));
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                intent.setClassName("com.google.android.apps.maps",
                        "com.google.android.maps.MapsActivity");
                startActivity(intent);
于 2013-05-17T11:39:38.073 回答