If you have questions or if you want to share your opinion about Aware IM post your message on this forum
#28938 by Gabbitas
Thu Jun 19, 2014 9:30 pm
Hi All,

I'm starting to experiment with the new distance function and trying to understand how it can be used. I have successfully managed to get the current location stored against the logged in user and I can create tracking records stored in a BO. I can also calculate and display the distance between the logged in user and a client address.

What I would really like to do is have a list of clients display that are close to the currently logged in user. Below is the rule inside a query that I've tried to use to accomplish this:

FIND Client WHERE (DISTANCE(Client.Address, LoggedInSystemUser.CurrentLocation)<1000)


When I run the query I get the following error:

"Internal error. Invalid parameters to DISTANCE function"


The Client.Address attribute is an address separated by commas eg streetname, town, county, postcode. I have tried removing the commas to see if that makes a difference but no luck. The SystemUser.CurrentLocation is just a geolocation string as stored by awareIM. I guess I'm most likely approaching this in the wrong way and/or the function can't be used inside the rules or a query.

Does any one have any ideas on where I'm going wrong here and how I might be able to display a list of clients close to the user? Also, in an ideal world it would be great to order the list with the closest client showing at the top of the list?

Thanks

#28944 by aware_support
Thu Jun 19, 2014 11:26 pm
Both parameters to the DISTANCE functions must be strings. The error message indicates that one of the parameters is not a string.

#28961 by Gabbitas
Sun Jun 22, 2014 10:46 am
Hi,

I use virtually the same rule and the same attributes to calculate and display the distance from the user to a single client address and this works fine so I'm confident that the parameters to the function are both strings.

After further studying the rule I'm tiring to use I just don't think it's written right. However, I can't figure out how to write this in a different way to get the result I need. If any one is able to make any suggestion on how I might achieve my goal I would be very grateful

Thanks

#28967 by Rennur
Mon Jun 23, 2014 5:39 am
Try using REPLACE_PATTERN but I'm not sure if it would with with the FIND action.

FIND Client WHERE (DISTANCE(REPLACE_PATTERN(Client.Address,',',' '), REPLACE_PATTERN(LoggedInSystemUser.CurrentLocation,',' '))<1000)

Or

Create a Not Persisted BO (Gmap) with the Gmap.ClientAddress and Gmap.CurrentLocation plain text attributes.

Then in your process you create the BO first and run the FIND action against this BO.

CREATE Gmap WITH Gmap.CurrentLocation=REPLACE_PATTERN(LoggedInSystemUser.CurrentLocation,',' '), Gmap.ClientLocation=REPLACE_PATTERN(Client.Address,',',' ')

FIND Client WHERE DISTANCE(Gmap.CurrentAddress, Gmap.ClientAddress)<1000

#29005 by yuri.rj
Fri Jun 27, 2014 2:41 pm
How did you get the CurrentLocation????

#29006 by yuri.rj
Fri Jun 27, 2014 2:42 pm
Sorry, my bad.... didn't know it already exist on AwareIM
#50627 by bondicoffee
Tue Mar 26, 2019 2:31 am
Hi,

We are getting the below error on using the Distance function in Awareim which was working earlier perfectly in earlier versions of AwareIM.

We are currently using Build 2571 v8.2. Following is the rule causing the below error :
Orders.Distance=DISTANCE(Orders.ps_FromAddress.Address,Orders.InstallationAddress)/1000

Can someone please advise if this is a known bug or we need to enable some setting in AwareIm?

XML returned by Google is <?xml version="1.0" encoding="UTF-8"?><DirectionsResponse> <status>REQUEST_DENIED</status> <error_message>You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account</error_message></DirectionsResponse>
java.lang.Exception: Status returned is REQUEST_DENIED
at com.bas.shared.functions.GoogleLibrary.calculateDistance(GoogleLibrary.java:182)
at com.bas.shared.functions.GoogleLibrary.calculate(GoogleLibrary.java:112)
at com.bas.basserver.executionengine.rliproc.SystemFunctionResolver.calculate(Unknown Source)
at com.bas.shared.ruleparser.ASTSystemFunction.calculate(ASTSystemFunction.java:152)
at com.bas.shared.ruleparser.ASTDivNode.calculate(ASTDivNode.java:92)
at com.bas.shared.ruleparser.ASTModifyActionStatement.calculate(ASTModifyActionStatement.java:431)
at com.bas.shared.ruleengine.ModifyAction.calculate(ModifyAction.java:200)
at com.bas.basserver.executionengine.rliproc.G.C(Unknown Source)
at com.bas.basserver.executionengine.rliproc.G.T(Unknown Source)
at com.bas.basserver.executionengine.rliproc.G.A(Unknown Source)
at com.bas.basserver.executionengine.rliproc.G.execute(Unknown Source)
at com.bas.basserver.executionengine.ExecutionEngine.A(Unknown Source)
at com.bas.basserver.executionengine.ExecutionEngine.A(Unknown Source)
at com.bas.basserver.executionengine.ExecutionEngine.A(Unknown Source)
at com.bas.basserver.executionengine.ExecutionEngine.doRecalculateObject(Unknown Source)
at com.bas.basserver.executionengine.ExecutionEngine.recalculateObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.bas.basserver.bsmanager.E.B(Unknown Source)
at com.bas.basserver.bsmanager.E.A(Unknown Source)
at com.bas.basserver.bsmanager.E.A(Unknown Source)
at com.bas.basserver.iopipes.ComponentSink.processMessage(Unknown Source)
at org.openadaptor.adaptor.STPipelineController.processMessage(STPipelineController.java:68)
at com.bas.openadaptor.NonTransactionalController.processMessage(NonTransactionalController.java:136)
at org.openadaptor.adaptor.AbstractSimplePipe.processMessage(AbstractSimplePipe.java:222)
at org.openadaptor.adaptor.STPipelineController.processMessage(STPipelineController.java:68)
at com.bas.openadaptor.NonTransactionalController.processMessage(NonTransactionalController.java:136)
at org.openadaptor.adaptor.AbstractSimpleSource.processMessage(AbstractSimpleSource.java:403)
at org.openadaptor.adaptor.AbstractSimpleSource.sourceProcess(AbstractSimpleSource.java:1049)
at org.openadaptor.adaptor.AbstractSimpleSource.sourceProcess(AbstractSimpleSource.java:1012)
at com.bas.openadaptor.MTJMSListener$JMSMessageHandler.run(MTJMSListener.java:275)
at java.lang.Thread.run(Thread.java:745)


Thanks in advance!
#50639 by aware_support
Wed Mar 27, 2019 5:42 am
This should be fixed in build 2573. You now need a third parameter to the DISTANCE function - Google Maps key. For example,

DISTANCE (Object.Location1, Object.Location2, SystemSettings.GoogleMapsKey)
#50642 by bondicoffee
Wed Mar 27, 2019 7:47 pm
Hi,

Thank you for the patch update. However, this is still not working.

I added a key in system settings and tried the below rule in test version as well as published version. However, I am getting the same error.


Following is rule updated :
Orders.Distance=DISTANCE(Orders.ps_FromAddress.Address,Orders.InstallationAddress,SystemSettings.GoogleMapsKey)/1000

Error:
Exception thrown com.bas.connectionserver.server.BASServerException com.bas.shared.ruleparser.ParseException Status returned is REQUEST_DENIED
com.bas.connectionserver.server.BASServerException: com.bas.shared.ruleparser.ParseException Status returned is REQUEST_DENIED
at com.bas.connectionserver.server.ConnectionFactory.sendMessage(ConnectionFactory.java:275)
at com.bas.connectionserver.server.ConnectionFactory.sendMessage(ConnectionFactory.java:233)
at com.bas.webapp.common.WebAppUtils.sendMessageToExecutionEngine(Unknown Source)
at com.bas.webapp.common.WebAppUtils.sendMessageToExecutionEngine(Unknown Source)
at com.bas.webapp.thin.handlers.C.O.A(Unknown Source)
at com.bas.webapp.thin.handlers.XMLRequestHandler.A(Unknown Source)
at com.bas.webapp.thin.handlers.XMLRequestHandler.handleRequest(Unknown Source)
at com.bas.webapp.thin.servlets.WebInterfaceServlet.doPost(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)


Looking forward to hearing from you.
#50645 by aware_support
Thu Mar 28, 2019 12:03 am
Did you specify a valid key?

What is the exact response returned by Google? (this response should be in the output of the Aware IM Server - just like in your original report - something like this:

XML returned by Google is <?xml version ....
#50647 by bondicoffee
Thu Mar 28, 2019 12:21 am
Apologies for sending incomplete error details.

Following is the error recieved :
XML returned by Google is <?xml version="1.0" encoding="UTF-8"?><DirectionsResponse> <status>REQUEST_DENIED</status> <error_message>Requests to this API must be over SSL. Load the API with &quot;https://&quot; instead of &quot;http://&quot;.</error_message></DirectionsResponse>
java.lang.Exception: Status returned is REQUEST_DENIED
at com.bas.shared.functions.GoogleLibrary.calculateDistance(GoogleLibrary.java:180)


I believe to fix this, the following code has to be fixed at com.bas.shared.functions.GoogleLibrary.java file which is present inside shared.jar file,
"String urlStr = "http://maps.googleapis.com/maps/api/directions/xml?origin=" +
URLEncoder.encode(addressFrom, "UTF-8") +
"&destination=" + URLEncoder.encode(addressTo, "UTF-8") +
"&units=metric&sensor=false";
"

Suggested change:
String urlStr = "https://maps.googleapis.com/maps/api/directions/xml?origin=" +
URLEncoder.encode(addressFrom, "UTF-8") +
"&destination=" + URLEncoder.encode(addressTo, "UTF-8") +
"&units=metric&sensor=false";
#52118 by yahya
Tue Nov 19, 2019 1:44 pm
Am doing a simple map using the predefined element where I am using a query to find a place and selecting the field with is a the location the field is a text.

Get this error message in the Java Console of the browser.

Geocoding Service: This API project is not authorized to use this API. For more information on authentication and Google Maps JavaScript API services please see: https://developers.google.com/maps/docu ... et-api-key js:70:128
xd https://maps.googleapis.com/maps/api/js ... *******:70
d https://maps.googleapis.com/maps-api-v3 ... coder.js:2
c https://maps.googleapis.com/maps-api-v3 ... mmon.js:69
<anonymous> https://maps.googleapis.com/maps/api/js ... ch?4sParis, France&7sUS&9sen-US&callback=_xdc_._ssnuog&key=AIzaSyCa9xifIxgz********************&token=32174:1
#52127 by yahya
Wed Nov 20, 2019 4:29 am
Did not have the Directions API enabled but now it is enabled, and now have got the following API's enabled, yet :
Cloud Messaging
Firebase Cloud Messaging API
Geolocation API
Maps JavaScript API
Maps SDK for Android
Maps SDK for iOS
Places API
Directions API

Geocoding Service: This API project is not authorized to use this API. For more information on authentication and Google Maps JavaScript API services please see: https://developers.google.com/maps/docu ... et-api-key js:70:128
xd https://maps.googleapis.com/maps/api/js ... *******:70
d https://maps.googleapis.com/maps-api-v3 ... coder.js:2
c https://maps.googleapis.com/maps-api-v3 ... mmon.js:69
<anonymous> https://maps.googleapis.com/maps/api/js ... ch?4sParis, France&7sUS&9sen-US&callback=_xdc_._ssnuog&key=AIzaSyCa9xifIxgz****************&token=21255:1

Who is online

Users browsing this forum: Google [Bot] and 20 guests