简体   繁体   中英

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. I have now enabled many more APIs than I would ever need and am still getting the same 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. 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. 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:

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. I am using Oracle JDeveloper 12c. No Maven-type helper was used.

Just for completeness sake, these are the APIs I have enabled:

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. This was a result of not using a Maven-like application.

I work with these libraries:

google-maps-services-0.1.1.jar -
okhttp-2.0.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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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