Hello Backendless Team -
I’m migrating my app from Parse to Backendless. Thank you for the amazing documentation.
I’m facing an issue with GeoLocation, hope you guys can help me move forward.
My app uses GeoLocation capabilities, I use Google API to find the Geo Location (lat, long) based on the Address user provides and update the same using the Custom Business Logic (JAVA). This API requires custom Jar files like google-maps-services.jar.
Here is the code snippet
@Asset( "Address" )
public class AddressTableEventHandler extends com.backendless.servercode.extension.PersistenceExtender<Address>
{
@Override
public void beforeCreate( RunnerContext context, Address address) throws Exception
{
LogBuffer.getInstance().setLogReportingPolicy(1, 0);
Logger logger = Logger.getLogger(AddressTableEventHandler.class);
String geoAddressString = address.getLines1() + " " + address.getCity() + " " + address.getState() + " " + address.getZip();
logger.info("geoAddressString is " + geoAddressString);
GeoApiContext geoContext = new GeoApiContext().setApiKey("....");
GeocodingResult[] results;
try {
results = GeocodingApi.geocode(geoContext, geoAddressString).await();
GeoPoint geoPoint = new GeoPoint(results[0].geometry.location.lat, results[0].geometry.location.lng);
geoPoint.addCategory("Address");
address.setGeolocation(geoPoint);
logger.info("geoPoint is " + geoPoint);
Backendless.Data.of(Address.class).save(address, new AsyncCallback<Address>() {
public void handleResponse(Address address) {
//this.logger.info("Handle Address Object Success!!");
System.out.println("Handle Address Object Success!!");
}
public void handleFault(BackendlessFault backendlessFault) {
//this.logger.error("Error Occured while Saving Address", backendlessFault.toString());
System.out.println("Handle Address Object Failure!!");
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
logger.error("Exception Occured while updating Address", e.fillInStackTrace());
//System.out.println("Exception Occured while updating Address" + e.getLocalizedMessage());
e.printStackTrace();
}
}
}
When i try to test the same using CodeRunner in local, i get the following error message.
Feb 29, 2016 12:41:42 AM com.backendless.coderunner.runtime.task.EventInvocationTask runImpl
SEVERE: Unresolved compilation problems:
The import com.google cannot be resolved
The import com.google cannot be resolved
The import com.google cannot be resolved
GeoApiContext cannot be resolved to a type
GeoApiContext cannot be resolved to a type
GeocodingResult cannot be resolved to a type
GeocodingApi cannot be resolved
java.lang.Error: Unresolved compilation problems:
The import com.google cannot be resolved
The import com.google cannot be resolved
The import com.google cannot be resolved
GeoApiContext cannot be resolved to a type
GeoApiContext cannot be resolved to a type
GeocodingResult cannot be resolved to a type
GeocodingApi cannot be resolved
at com.backendless.trackdayshub.events.persistence_service.AddressTableEventHandler.<init>(AddressTableEventHandler.java:15)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at com.backendless.coderunner.runtime.task.EventInvocationTask.runImpl(EventInvocationTask.java:72)
at com.backendless.coderunner.runtime.concurrent.ExtendedRunnable.run(ExtendedRunnable.java:22)
at java.lang.Thread.run(Thread.java:745)
I pushed the changes to Production using the Deploy.sh script, i see the new Class file and JAR files under lib directory but I dont see this piece of code getting executed.
Can you please advice?