GoogleMaps отрисовка пути и FrameLayout

столкнулся с проблемой связанной с постройкой пути между двумя точками, использую 1 активность и 4 фрейма, на 1 из них красуется Google Maps, все точки которые я получаю с БД отображаются корректно. Но при попытке отрисовать линии возникают следующие моменты, а именно.

>  java.lang.ClassCastException:
> com.example.mytusurgooglemap.MainActivity cannot be cast to directionhelpers.TaskLoadedCallback
>             at directionhelpers.PointsParser.<init>(PointsParser.java:26)
>             at directionhelpers.FetchURL.onPostExecute(FetchURL.java:46)
>             at directionhelpers.FetchURL.onPostExecute(FetchURL.java:19)

Скриншоты и код самого вызова прилагаются, так же есть ссылка на ГИТ откуда я брал классы для дополнения своей программы. https://github.com/Vysh01/android-maps-directions Возможно я не так использую фреймы, но пока что учусь, буду рад помощи и объяснению, в чем я ошибся. Скришноты прилагаются. Метод Draw для запросов.

public void Draw () {
        String url = getUrl(myPlace.getPosition(),sightPlace.getPosition(),"driving");
        new FetchURL(getContext()).execute(url,"driving");
    }

    private String getUrl ( LatLng origin,LatLng dest, String directionMode){
        String str_origin =  "origin=" + origin.latitude +","+origin.longitude;
        String str_dest = "destination=" + dest.latitude + ","+dest.longitude;
        String mode = "mode=" + directionMode;
        String parameters = str_origin + "&" + str_dest + "&"+ mode;
        String output = "json";
        String url = "https://maps.googleapis.com/maps/api/directions/" + output +"?"+parameters + "&key="+getString(R.string.google_api_key);
        Log.e("URL" , url);
        return url;
    }

    @Override
    public void onTaskDone(Object... values) {
        if(currentPolyline !=null){
            currentPolyline.remove();
            currentPolyline = mMap.addPolyline((PolylineOptions) values[0]);
        }
    }

Код PointParser выделил где ругается

public class PointsParser extends AsyncTask<String, Integer, List<List<HashMap<String, String>>>> {
    TaskLoadedCallback taskCallback;
    String directionMode = "driving";

    public PointsParser(Context mContext, String directionMode) {
        this.taskCallback = (TaskLoadedCallback) mContext; //Ругается тут
        this.directionMode = directionMode;
    }

    // Parsing the data in non-ui thread
    @Override
    protected List<List<HashMap<String, String>>> doInBackground(String... jsonData) {

        JSONObject jObject;
        List<List<HashMap<String, String>>> routes = null;

        try {
            jObject = new JSONObject(jsonData[0]);
            Log.d("mylog", jsonData[0].toString());
            DataParser parser = new DataParser();
            Log.d("mylog", parser.toString());

            // Starts parsing data
            routes = parser.parse(jObject);
            Log.d("mylog", "Executing routes");
            Log.d("mylog", routes.toString());

        } catch (Exception e) {
            Log.d("mylog", e.toString());
            e.printStackTrace();
        }
        return routes;
    }

    // Executes in UI thread, after the parsing process
    @Override
    protected void onPostExecute(List<List<HashMap<String, String>>> result) {
        ArrayList<LatLng> points;
        PolylineOptions lineOptions = null;
        // Traversing through all the routes
        for (int i = 0; i < result.size(); i++) {
            points = new ArrayList<>();
            lineOptions = new PolylineOptions();
            // Fetching i-th route
            List<HashMap<String, String>> path = result.get(i);
            // Fetching all the points in i-th route
            for (int j = 0; j < path.size(); j++) {
                HashMap<String, String> point = path.get(j);
                double lat = Double.parseDouble(point.get("lat"));
                double lng = Double.parseDouble(point.get("lng"));
                LatLng position = new LatLng(lat, lng);
                points.add(position);
            }
            // Adding all the points in the route to LineOptions
            lineOptions.addAll(points);
            if (directionMode.equalsIgnoreCase("walking")) {
                lineOptions.width(10);
                lineOptions.color(Color.MAGENTA);
            } else {
                lineOptions.width(20);
                lineOptions.color(Color.BLUE);
            }
            Log.d("mylog", "onPostExecute lineoptions decoded");
        }

        // Drawing polyline in the Google Map for the i-th route
        if (lineOptions != null) {
            //mMap.addPolyline(lineOptions);
            taskCallback.onTaskDone(lineOptions);

        } else {
            Log.d("mylog", "without Polylines drawn");
        }
    }
}

PointsParser

И код FetchURL

public class FetchURL extends AsyncTask<String, Void, String> { //Ругается ТУТ
    @SuppressLint("StaticFieldLeak")
    Context mContext;
    String directionMode = "driving";

    public FetchURL(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    protected String doInBackground(String... strings) {
        // For storing data from web service
        String data = "";
        directionMode = strings[1];
        try {
            // Fetching the data from web service
            data = downloadUrl(strings[0]);
            Log.d("mylog", "Background task data " + data.toString());
        } catch (Exception e) {
            Log.d("Background Task", e.toString());
        }
        return data;
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        PointsParser parserTask = new PointsParser(mContext, directionMode); //Ругается ТУТ
        // Invokes the thread for parsing the JSON data
        parserTask.execute(s);
    }

    private String downloadUrl(String strUrl) throws IOException {
        String data = "";
        InputStream iStream = null;
        HttpURLConnection urlConnection = null;
        try {
            URL url = new URL(strUrl);
            // Creating an http connection to communicate with url
            urlConnection = (HttpURLConnection) url.openConnection();
            // Connecting to url
            urlConnection.connect();
            // Reading data from url
            iStream = urlConnection.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
            StringBuffer sb = new StringBuffer();
            String line = "";
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
            data = sb.toString();
            Log.d("mylog", "Downloaded URL: " + data.toString());
            br.close();
        } catch (Exception e) {
            Log.d("mylog", "Exception downloading URL: " + e.toString());
        } finally {
            iStream.close();
            urlConnection.disconnect();
        }
        return data;
    }
}

FetchURL


Ответы (0 шт):