android get and parse Google Directions

后端 未结 4 1482
没有蜡笔的小新
没有蜡笔的小新 2020-12-14 22:16

google Directions API

I read this guide now I can build a correct request to receive the xml file containg the directions from address A to address B. What I need is

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 22:59

    I found this example on the web I'll try to use it. polyline decoding example

    private List decodePoly(String encoded) {
    
      List poly = new ArrayList();
      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;
    }
    

提交回复
热议问题