2010-07-17 2 views
4

저는 Android 앱을 작성 중이며 위도/경도 값을 가져 와서 가장 가까운 도로의 위도/경도 값을 찾아야합니다. 나는 http://econym.org.uk/gmap/snap.htm에서 기사를 읽었으며이를 구현하려고 시도했지만 자바 스크립트가 아닌 Google Maps Webservices를 사용해야했습니다 (Android 앱이므로). 내가Android에 도로 맞추기

maps.google.com/maps/api/directions/xml?origin=52.0,0 & 목적지에 같은 요청을 = 52.0,0 & 센서 = 사실이 나야을 반환하지 않습니다

가장 가까운 길! 위의 방법이 웹 서비스에서 작동하지 않는 것 같습니다. 누구든지이 문제를 해결하는 방법에 대한 다른 아이디어가 있습니까?

답변

4

URL이 완벽하게 작동하는 것 같습니다.

여기 테스트하기 위해 사용한 AsyncTask가 있습니다.

11-07 16:20:42.880: V/SnapToRoad(13920):  <start_location> 
11-07 16:20:42.880: V/SnapToRoad(13920):  <lat>51.9999900</lat> 
11-07 16:20:42.880: V/SnapToRoad(13920):  <lng>0.0064800</lng> 
11-07 16:20:42.880: V/SnapToRoad(13920):  </start_location> 

그들은 당신이 찾고있는 좌표는 다음 로그 캣 출력 내에서

public class SnapToRoad extends AsyncTask<Void, Void, Void> { 

private static final String TAG = SnapToRoad.class.getSimpleName(); 

@Override 
protected Void doInBackground(Void... params) { 
    Reader rd = null; 
    try { 
     URL url = new URL("http://maps.google.com/maps/api/directions/xml?origin=52.0,0&destination=52.0,0&sensor=true"); 
     HttpURLConnection con = (HttpURLConnection) url.openConnection(); 
     con.setReadTimeout(10000 /* milliseconds */); 
     con.setConnectTimeout(15000 /* milliseconds */); 
     con.connect(); 
     if (con.getResponseCode() == 200) { 

      rd = new InputStreamReader(con.getInputStream()); 
      StringBuffer sb = new StringBuffer(); 
      final char[] buf = new char[1024]; 
      int read; 
      while ((read = rd.read(buf)) > 0) { 
       sb.append(buf, 0, read); 
      } 
      Log.v(TAG, sb.toString()); 
     } 
     con.disconnect(); 
    } catch (Exception e) { 
     Log.e("foo", "bar", e); 
    } finally { 
     if (rd != null) { 
      try { 
       rd.close(); 
      } catch (IOException e) { 
       Log.e(TAG, "", e); 
      } 
     } 
    } 
    return null; 
} 

당신은 당신이 볼 수 몇 줄을 보면. 도움이되기를 바랍니다.