【问题标题】:Google Geocoding API returning illegalaccesserror谷歌地理编码 API 返回非法访问错误
【发布时间】:2015-05-06 20:00:22
【问题描述】:

我当然希望你能帮上忙,我已经走到了尽头。我昨天发布了这个问题,但很快就被否决了,因为我将我正在做的事情称为距离矩阵 API,并且立即假设我只是在谷歌中启用了错误的 API。我现在启用的 API 比我需要的多得多,但仍然收到相同的 IllegalAccessError:

May 06, 2015 12:48:16 PM com.google.maps.GeoApiContext setQueryRateLimit
INFO: Configuring rate limit at QPS: 10, minimum delay 50ms between requests
Exception in thread "AWT-EventQueue-0" java.lang.IllegalAccessError: tried     to access class com.squareup.okhttp.Dispatcher from class com.google.maps.GeoApiContext
at com.google.maps.GeoApiContext.setQueryRateLimit(GeoApiContext.java:224)
at com.google.maps.GeoApiContext.setQueryRateLimit(GeoApiContext.java:210)
at com.google.maps.GeoApiContext.<init>(GeoApiContext.java:56)
at budgetrouting.MapPane.<init>(MapPane.java:27)
at budgetrouting.BudgetRouting$1.run(BudgetRouting.java:19)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Process exited with exit code 0.

我的代码:

    GeoApiContext context = new GeoApiContext();
    context.setApiKey(APIKey);
    GeocodingResult[] results;
    try {
        results = GeocodingApi.geocode(context, "1600 Amphitheatre Parkway Mountain View, CA 94043").await();
    System.out.println(results[0].formattedAddress);
    } catch (Exception e) {
        e.printStackTrace();
    }

我已经阅读了有关此错误的所有信息以及它与 google api 的关系,但到目前为止我还没有任何明确的答案。我认为这是一个错误而不是异常这一事实意味着它可能与我的访问权限没有任何关系,特别是因为错误发生在我设置我的 API 密钥之前的那一行。由于 IllegalAccessError 的定义声明“如果类的定义发生了不兼容的更改,此错误只会在运行时发生”,我将包含我的依赖项:

google-maps-services-0.1.1.jar
okhttp-1.2.1-jar-with-dependencies.jar

我已经检查了 okhttp 的完整性,并且错误中提到的类确实存在。我正在使用 Oracle JDeveloper 12c。没有使用 Maven 类型的帮助器。

为了完整起见,以下是我启用的 API:

BigQuery API
Debuglet Controller API
Directions API
Distance Matrix API
Elevation API
Geocoding API
Google Cloud Logging API
Google Cloud SQL
Google Cloud Storage
Google Cloud Storage JSON API
Google Maps Embed API
Google Maps Engine API
Time Zone API

有什么想法吗?谢谢!

【问题讨论】:

    标签: java google-maps google-api geocoding


    【解决方案1】:

    我收到上述错误的原因是 google-maps-services-0.1.1.jar 需要 okhttp 2.0.0,而不是 okhttp-1.2.1-jar-with-dependencies.jar 以及其他一些事物。这是因为没有使用类似 Maven 的应用程序。

    【讨论】:

      【解决方案2】:

      我使用这些库:

      google-maps-services-0.1.1.jar -
      okhttp-2.0.0.jar -
      okio-1.11.0.jar -

      示例代码:

      public String obtenerLatitudLongitud (String direccion) throws Exception{
      
          try {
              GeoApiContext context = new GeoApiContext().setApiKey(this.propiedades.get(ConstantesApi.KEY_MAPS_GOOGLE));
              context.setQueryRateLimit(50);
              GeocodingResult[] results =  GeocodingApi.geocode(context,direccion).await();
              latLong = results[0].geometry.location.toString();
              logger.debug("Latitud, longitud   : "  + latLong);
          } catch (Exception e) {
              logger.error("Error Normalizando la direccion :  "  +  direccion  +  "  " + e.getMessage());
          }
      
          return latLong;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-23
        • 1970-01-01
        • 1970-01-01
        • 2012-04-10
        • 1970-01-01
        相关资源
        最近更新 更多