2013-05-17 2 views
-1

Google지도 애플리케이션에서 작업 중이며 두 지점 사이의 경로를 찾는 코드를 사용합니다. Android 2.3.3에서 정상적으로 작동합니다. 하지만 지금은 Android 4.0.3에 테스트 중이며 충돌이 발생합니다. 나는 그것이 AsyncTask에서 변환 될 필요가 있지만 그렇게 할 수는 없다. 내가 가진 내 DirectionClass에서Android 4.03에서 Google 방향 코드가 작동하지 않습니다.

,

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) 

답변

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); 
관련 문제