简体   繁体   English

Google Geocoding API返回非法访问错误

[英]Google Geocoding API returning illegalaccesserror

I sure hope you can help, I am getting towards the end of my rope. 我肯定希望您能提供帮助,我已经快要走到尽头了。 I posted this question yesterday but was quickly down-voted because I referred to what I was doing as Distance Matrix API and it was immediately assumed I had simply enabled the wrong API in google. 我昨天发布了这个问题,但很快就被否决了,因为我将自己正在做的事情称为距离矩阵API,并且立即认为我只是在google中启用了错误的API。 I have now enabled many more APIs than I would ever need and am still getting the same IllegalAccessError: 现在,我已经启用了比我需要的更多的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.

My code: 我的代码:

    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();
    }

I have read every scrap of information on this error and how it relates to google api, but so far I don't have any definitive answers. 我已经阅读了有关此错误及其与google api的关系的所有信息,但到目前为止,我没有任何明确的答案。 I think that the fact that it is an error and not an exception means that it may not have anything to do with my access rights, especially since the error occurs the line before I set my API key. 我认为这是一个错误而不是一个例外,这意味着它可能与我的访问权限无关,尤其是因为该错误发生在我设置API密钥之前的那一行。 Since the definition of IllegalAccessError states "this error can only occur at run time if the definition of a class has incompatibly changed," I will include my dependencies: 由于IllegalAccessError的定义指出“只有在类的定义发生不兼容的更改时,此错误才能在运行时发生”,因此,我将包括我的依赖项:

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

I have checked okhttp for integrity and the class mentioned in the error does exist. 我已经检查了okhttp的完整性,并且错误中提到的类确实存在。 I am using Oracle JDeveloper 12c. 我正在使用Oracle JDeveloper 12c。 No Maven-type helper was used. 没有使用Maven类型的帮助程序。

Just for completeness sake, these are the APIs I have enabled: 出于完整性考虑,以下是我启用的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

Any ideas? 有任何想法吗? Thanks! 谢谢!

The reason I was getting the above error was that google-maps-services-0.1.1.jar requires okhttp 2.0.0, not okhttp-1.2.1-jar-with-dependencies.jar, along with a few other things. 我收到上述错误的原因是google-maps-services-0.1.1.jar需要okhttp 2.0.0,而不是okhttp-1.2.1-jar-with-dependencies.jar,以及其他一些东西。 This was a result of not using a Maven-like application. 这是因为未使用类似Maven的应用程序。

I work with these libraries: 我使用以下库:

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

Example code: 示例代码:

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM