首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google Direction api

Google Direction api
EN

Stack Overflow用户
提问于 2018-08-16 15:10:23
回答 1查看 643关注 0票数 0

我正在我的android应用程序中实现google direction api。它可以工作,但它需要时间(大约30秒)来获取result.How我可以减少这个获取时间。我在google控制台上启用了google direction api,但在那里,我得到了google direction api的99%的错误率。

代码语言:javascript
复制
  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);


}
EN

回答 1

Stack Overflow用户

发布于 2018-08-16 15:18:40

当将1s设置为所有可能的超时值时,大多数尝试可能只是超时。

..。最好尝试使用GeoApiContext.Builder()的默认设置:

代码语言:javascript
复制
private GeoApiContext getGeoApiContext() {
    return new GeoApiContext.Builder()
      .apiKey(getResources().getString(R.string.apikey))
      .build();
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51871475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档