2017-11-08 12 views
0

안드로이드 맵에서 폴리 포인트를 어떻게 표시 할 수 있습니까? 이것은 방향 API에서 얻은 JSON 샘플입니다. 나는 overview_polyline을 android map에 그려 넣고 싶다. LatLng를 사용하여 android maps polyline을 추가합니다. 여기 안드로이드에서 웹 서비스 google direction api를 사용할 수 있습니까? 그렇다면 어떻게 맵에 폴 포인트를 표시 할 수 있습니까?

샘플을 인 JSON

https://codebeautify.org/jsonviewer/cb8d34d5

답변

1

참조 - http://javapapers.com/android/draw-path-on-google-maps-android-api/

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; 
    }