Reputation: 139
I am implementing google direction api in my android app. It works but it takes time(approx 30sec) to fetch result.How can I reduce this fetching time. I had enable google direction api on google console but there, I am getting 99% error rate for google direction api.
private DirectionsResult getDirectionsDetails(String origin, String destination, TravelMode mode) {
mMap.clear();
DateTime now = new DateTime();
try {
return DirectionsApi.newRequest(getGeoContext())
.mode(mode)
.origin(origin)
.destination(destination)
.departureTime(now)
.await();
} catch (ApiException e) {
e.printStackTrace();
return null;
} catch (InterruptedException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
private GeoApiContext getGeoContext() {
GeoApiContext geoApiContext = new GeoApiContext();
return geoApiContext
.setQueryRateLimit(3)
.setApiKey(getResources().getString(R.string.apikey))
.setConnectTimeout(1, TimeUnit.SECONDS)
.setReadTimeout(1, TimeUnit.SECONDS)
.setWriteTimeout(1, TimeUnit.SECONDS);
}
Upvotes: 0
Views: 718
Reputation: 76809
most of your attempts might just timeout, when setting 1s
as all possible timeout values.
... better try to use the GeoApiContext.Builder()
with it's default settings:
private GeoApiContext getGeoApiContext() {
return new GeoApiContext.Builder()
.apiKey(getResources().getString(R.string.apikey))
.build();
}
Upvotes: 1