2009-10-23 4 views

답변

2

답변은 TeleNav 또는 누군가로부터 수백만 달러짜리 라이센스에 가입하는 것으로 의심됩니다.

API를 가져온 이유는 Google 자체가 TeleNav 또는 다른 회사로부터이 데이터를 라이센스하기 때문에 운전 방향을 통해 수행 할 수있는 작업에 제한이 있기 때문입니다 (예 : 실시간 turn-by-turn 작업을 수행 할 수 없음). . Google은 개발자가 이러한 제한된 작업을 수행하도록 허용 할 수 없으며 공개 API를이 경우 적절히 보호 할 수 없습니다.

오픈 스트리트 맵에는 운전 경로 FWIW가 있다는 언급이 있습니다.

2

아마도 조금 늦었 겠지만 다른 사람들에게 여전히 도움이됩니다. 내가 얻을 안드로이드에 대한지도보기에서 운전 경로를 표시하기 위해 몇 가지 간단한 클래스를 작성했습니다 :

http://home.ameliemedia.com/android-app-aroundme/#tips

는 희망이 도움이!

안드레아.

+0

Andrea, 해당 URL은 예제 코드를 제공하지 않습니다. 도메인 등록이 만료 된 것처럼 보입니다. 다른 곳에서 사용할 수 있습니까? –

0

구글에서 현재 솔루션은 Google Maps API Web Services을 사용하는 것입니다 참조하십시오. 제한된 사용을 위해 무료; (성공적인) 상용 사용료를 지불해야합니다.

4

포인트가 필요한 라인이 필요한 경우 전체 kml이 필요하지 않습니다. 훨씬 빠른 방법은 dragdir = 그것은 단지 JSON 출력 Google지도 API에서 반환 사용하는 것입니다 수행하는

private String getUrl(String start, String end) { 
    //If params GeoPoint convert to lat,long string here 
    StringBuffer urlString = new StringBuffer(); 
    urlString.append("http://maps.google.com/maps?f=d&hl=en"); 
    urlString.append("&saddr=");// from 
    urlString.append(start); 
    urlString.append("&daddr=");// to 
    urlString.append(end); 
    urlString.append("&ie=UTF8&0&om=0&output=dragdir"); //DRAGDIR RETURNS JSON 
    Log.i("URLString", urlString.toString()); 
    return urlString.toString(); 
} 
이 URLString는이 문자열의 분할을 사용하여 쉽게 정보를 추출 할 수있는 JSON 파일을 가져올 수 있습니다

private String getConnection(String url) { 
    URL inUrl = new URL(url); 
    URLConnection yc = inUrl.openConnection(); 
    BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); 
    String inputLine; 
    String encoded = ""; 
    while ((inputLine = in.readLine()) != null) 
     encoded = encoded.concat(inputLine); 
    in.close(); 
    String polyline = encoded.split("points:")[1].split(",")[0]; 
    polyline = polyline.replace("\"", ""); 
    polyline = polyline.replace("\\\\", "\\"); 
    return polyline; 
} 

반환되는 문자열은 아래 방법을 사용하여 Geopoint 목록으로 디코딩 할 수있는 폴리 라인입니다.

private static ArrayList<GeoPoint> decodePolyline(String encoded) { 
    ArrayList<GeoPoint> geopoints = new ArrayList<GeoPoint>(); 
    int index = 0, len = encoded.length(); 
    int lat = 0, lng = 0; 
    while (index < len) { 
     int b, shift = 0, result = 0; 
     do { 
      b = encoded.charAt(index++) - 63; 
      result |= (b & 0x1f) << shift; 
      shift += 5; 
     } while (b >= 0x20); 
     int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); 
     lat += dlat; 
     shift = 0; 
     result = 0; 
     do { 
      b = encoded.charAt(index++) - 63; 
      result |= (b & 0x1f) << shift; 
      shift += 5; 
     } while (b >= 0x20); 
     int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); 
     lng += dlng; 
     GeoPoint p = new GeoPoint((int) (((double) lat/1E5) * 1E6), (int) (((double) lng/1E5) * 1E6)); 
     geopoints.add(p); 
    } 
return geopoints; 
} 

마지막 단계는 그것을 위해 우리가 GeoPoints의 ArrayList를 처리 할 오버레이 항목을 필요로하는지도보기에 이러한 점을 그릴 것입니다.

public class PathOverlay extends Overlay { 

    private ArrayList<GeoPoint> pointList; 

    public PathOverlay(ArrayList<GeoPoint> pointList) { 
      this.pointList = pointList;  
    } 

    @Override 
    public void draw(Canvas canvas, MapView mapView, boolean shadow) { 
     Point current = new Point(); 
     Path path = new Path(); 
     Projection projection = mapView.getProjection(); 
     Iterator<GeoPoint> iterator = pointList.iterator(); 
     if (iterator.hasNext()) { 
      projection.toPixels(iterator.next(), current); 
      path.moveTo((float) current.x, (float) current.y); 
     } else return; 
     while(iterator.hasNext()) { 
      projection.toPixels(iterator.next(), current); 
      path.lineTo((float) current.x, (float) current.y); 
     } 

     Paint pathPaint = new Paint(); 
     pathPaint.setAntiAlias(true); 
     pathPaint.setStrokeWidth(3.0f); 
     pathPaint.setColor(Color.GREEN); 
     pathPaint.setStyle(Style.STROKE); 
     canvas.drawPath(path, pathPaint); 
    } 
} 

등의지도보기에 오버레이를 얻는 방법 또는 라우터 클래스를 알려 주시면 당신에게 전체 코드를 보낼 수 있습니다 설정하는 방법으로 중간 단계의 일부에 대해 확실하지 않은 경우.