Expand my Community achievements bar.

SOLVED

Google maps

Avatar

Level 2

I'm using 6.5.18 and trying to call the google maps api from backend. As part of it, I have added the below dependency.

 

<dependency>
<groupId>com.google.maps</groupId>
<artifactId>google-maps-services</artifactId>
<version>2.2.0</version>
<scope>provided</scope>
</dependency>

After bundle installation, I'm getting the follwing error -> com.google.maps & com.google.maps.model -- Cannot be resolved.

After referring this https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/google-maps-service/m-p/28... , I have tried wrapping the bundle, but end up with the same error. Below is the code I used to wrap.

 

<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<executions>
<execution>
<configuration>
<bnd><![CDATA[
Import-Package: javax.annotation;version=0.0.0, \
com.day.cq.search;version="[1.3.0,2)", \
com.day.cq.wcm.api;version="[1.27.0,2)", \
org.apache.commons.lang3;version="[3.9.0,4)", \
org.apache.sling.api.resource;version="[2.11.1,3)", \
*
-conditionalpackage: com.google.maps.*
-includeresource: google-maps-services-2.2.0.jar!/
]]></bnd>
</configuration>
</execution>
</executions>

Below is the servlet, I'm trying.

@SlingServletPaths("/bin/public/googlemap/geocoding")
public class GoogleMapApiServlet extends BasePostServlet {
private static final long serialVersionUID = -5329046579625621392L;
private final Logger LOGGER = LoggerFactory.getLogger(GoogleMapApiServlet.class);
@Reference
private GeoApiContext geoApiContext;

@Override
protected void doGet(final SlingHttpServletRequest request,
final SlingHttpServletResponse response) {
try {
LOGGER.info("== Inside Google Map Api Servlet ==");
geoApiContext = new GeoApiContext.Builder().apiKey("KEY") .build();
String address = "1600 Amphitheatre Parkway Mountain View, CA 94043";

GeocodingResult[] results = GeocodingApi.geocode(geoApiContext, address).await();
} catch (Exception e) {
LOGGER.error("== Error in Google Map Api ==", e);
}
}
}

 

Can someone please help with the inputs if you gone through this scenario?

@AkshaySwamii @smacdonald2008 @Peter_Puzanovs @robin_wadhwa 

Regards,

Vijay

 

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

The issue got resolved by installing the google-maps-services-2.2.0.jar and the bundle is now active. But ended with Class not found exception!

 

Caused by: java.lang.ClassNotFoundException: okhttp3.Interceptor not found by google-maps-2.1.0 [642]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1597)
at org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1982)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 158 common frames omitted

I have tried, with 2.1.0, 2.1.2 & 2.2.0. All the jar has the same issue. And there was an another blog reporting the same issue https://github.com/googlemaps/google-maps-services-java/issues/832 

 

Regards,
Vijay

View solution in original post

1 Reply

Avatar

Correct answer by
Level 2

The issue got resolved by installing the google-maps-services-2.2.0.jar and the bundle is now active. But ended with Class not found exception!

 

Caused by: java.lang.ClassNotFoundException: okhttp3.Interceptor not found by google-maps-2.1.0 [642]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1597)
at org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1982)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 158 common frames omitted

I have tried, with 2.1.0, 2.1.2 & 2.2.0. All the jar has the same issue. And there was an another blog reporting the same issue https://github.com/googlemaps/google-maps-services-java/issues/832 

 

Regards,
Vijay