1

I'm using the following code to get the direction between two points on Google Maps:

Callback<Direction> directionCallback = new Callback<Direction>() {
    @Override
    public void onResponse(@NonNull Call<Direction> call, @NonNull Response<Direction> response) {
        if (response != null) {
            if (response.isSuccessful()) {
                Direction direction = response.body();
                Log.d("TAG", response.raw());
                if (direction != null) {
                    List<Route> routes = direction.routes;
                    if (routes.size() > 0) {
                        //Get first route
                    } else {
                        Log.d("TAG", "routes.size() = 0");
                    }
                }
            } else {
                Log.d("TAG", response.errorBody().toString());
            }
        }
    }

    @Override
    public void onFailure(@NonNull Call<Direction> call, @NonNull Throwable t) {
        Log.d("TAG", t.getMessage());
    }
};
directionCall.enqueue(directionCallback);

This code works perfectly fine when I run my app from Android Studio on a phone or emulator, however, when I update the app in Google Play, the body of the Retrofit call becomes empty, getting as result:

routes.size() = 0

If if log response.raw(), I get the following response:

Response{
  protocol=h2,
  code=200,
  message=,
  url=https://maps.googleapis.com/maps/api/directions/json?origin=11.1741765%2C22.6436729&destination=11.189821%2C22.640532&mode=walking&key=LongKey
}

If I click on that link, I get the desired JSON file, but the body is empty. No error message. Does anyone know what the problem might be?

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • I clicked on the link, it says I don't have api key. Is the link the error or your call. Better if u show us the response from the link – Jason Jun 12 '20 at 10:38
  • @Jason The key that I'm using is correct, but I'm not gonna make it public, as it's for a live project. If I change `LongKey` with the real key, I get the correct page. – Alex Mamo Jun 12 '20 at 10:43
  • @AlexMamo check this StackOverflow [answer](https://stackoverflow.com/a/44672565/5180017). – Shashanth Jun 13 '20 at 04:39
  • @Shashanth if the key wasn't there, there would be an error message. – MrUpsidown Jun 27 '20 at 19:23

0 Answers0