Подтвердить что ты не робот

Android получить и разобрать Google Directions

API Google Адресов

Теперь я прочитал это руководство. Я могу создать правильный запрос на получение xml файла, связанного с адресами от адреса A до адреса B. Что мне нужно, это некоторые инструкции и пример того, как читать этот xml, чтобы нарисовать полученные направления на Android MapView. Я также хотел бы знать, что представляет этот тег в xml:

<overview_polyline>
<points>
[email protected][email protected]`vnApw{A`[email protected]~w\|[email protected]{[email protected]@b}
@[email protected][email protected]@jc|Bx}C`[email protected]|@[email protected]}Axf][email protected]
[email protected]{A~d{A|[email protected]`cFp~xBc`[email protected]@[email protected][email protected]
[email protected][email protected]|{CbtY~jGqeMb{iF|n\~mbDzeVh_Wr|Efc\x`Ij{kE}mAb~uF{cNd}xBjp]
[email protected]|[email protected]_Kv~eGyqTj_|@`uV`k|[email protected]}[email protected][email protected]`CnvH
x`[email protected]@j|[email protected]|[email protected]`[email protected][email protected]}pIlo_B
[email protected]`@|}[email protected]@jakEitAn{fB_a]lexClshBtmqAdmY_hLxiZd~XtaBndgC
</points>
<levels>BBBAAAAABAABAAAAAABBAAABBAAAABBAAABABAAABABBAABAABAAAABABABABBABAABB</levels> 
</overview_polyline> 

спасибо

4b9b3361

Ответ 1

Я нашел этот пример в Интернете, я попытаюсь его использовать. пример декодирования полилинии

private List<GeoPoint> decodePoly(String encoded) {

  List<GeoPoint> poly = 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));
      poly.add(p);
  }

  return poly;
}

Ответ 2

Я также пытался использовать Direction Api для Google на Android. Поэтому я сделал проект с открытым исходным кодом, чтобы помочь в этом. Вы можете найти его здесь: https://github.com/MathiasSeguy-Android2EE/GDirectionsApiUtils

Как это работает, определенно просто:

public class MainActivity extends ActionBarActivity implements DCACallBack{
/**
 * Get the Google Direction between mDevice location and the touched location using the     Walk
 * @param point
 */
private void getDirections(LatLng point) {
     GDirectionsApiUtils.getDirection(this, startPoint, endPoint, GDirectionsApiUtils.MODE_WALKING);
}

/*
 * The callback
 * When the directions is built from the google server and parsed, this method is called and give you the expected direction
 */
@Override
public void onDirectionLoaded(List<GDirection> directions) {        
    // Display the direction or use the DirectionsApiUtils
    for(GDirection direction:directions) {
        Log.e("MainActivity", "onDirectionLoaded : Draw GDirections Called with path " + directions);
        GDirectionsApiUtils.drawGDirection(direction, mMap);
    }
}

Ответ 3

Я подправил urobo ответ выше (очень немного), чтобы дать вам LatLngs, который вы хотите использовать для Карт Google для Android V2:

private List<LatLng> decodePoly(String encoded) {

    List<LatLng> poly = new ArrayList<LatLng>();
    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;

        LatLng p = new LatLng((double) lat / 1E5, (double) lng / 1E5);
        poly.add(p);
    }
    return poly;
}

Ответ 4

вам может потребоваться быстрый просмотр маршрута, который будет создан с помощью waypoint_polyline и списка координат напрямую. Для этого google имеет декодирование выпуска api "Интерактивная утилита кодирования полилинии"

Вы можете вставить значение waypoint_polyline в текстовое поле Кодированная полилиния по адресу Интерактивная утилита Polyline Encoder