I have my API to calculate the distance. However, I am unable to get the codes to use the API. I am novice in android.Please provide the codes to use the API. I was using the latitude longitude but distance was not showing correctly. Guys help!
public String[] Distance(final double lat1, final double lon1, final double lat2, final double lon2) {
    final String[] parsedDistance = new String[1];
    final String[] response = new String[1];
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Request request = new Request.Builder()
                        .url("https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=lat1%2Clon1&destinations=lat2%2Clon2")
                        .get()
                        .addHeader("key", "AIzaSyBP1g2YfJmsZ8zVhQBKffnGxL7TyqTYFxk")
                        .addHeader("cache-control", "no-cache")
                        .build();
            } catch (ProtocolException e) {
                e.printStackTrace();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
    thread.start();
    try {
        thread.join();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return parsedDistance;
}
 
    