[Location Plugin] How do I actually GET the location in my mobile app

Forge Component
(22)
Published on 3 Apr by OutSystems R&D
22 votes
Published on 3 Apr by OutSystems R&D

So I've got my basic "ToDo" application that I created with the Outsystems basic tutorial. I added a decimal type LAT and LNG to my ToDo record in the database. In my interface in the SaveOnClick action I call a "CreateorUpdateToDoWrapper" server action. That action has the "CreateorUpdateToDo" action that comes with my entity. I manually set the userID attribute inside the wrapper action by dragging an assignment after Start and setting ToDo.UserID = GetUserID(), getuserID() being a built in function. I figure that to save the Lat and Long I would just have to do something similar.

 I want to set the ToDo.LAT and ToDo.LNG inside this wrapper function. For the assignment, I set the object I'm assigning to ToDo.Lat and then I figure I can just set the value to the Latitude from the Location returned by the "GetLocation" method of the location plugin. 

No can do. 


In the expression editor when I try to set the value/assignment of "ToDo.Lat", the LocationPlugin actions don't show up at all. The options I have shows a root "SCOPE" and under that I just have Entities, Site, Roles, User Function, Built in Functions, and Scripts. How do I do something super simplelike just setting the value of something to what's returned by the LocationPlugin's GetLocation action?


I'm trying to evaluate if Outsystems is right for my company, but my biggest peeve is that functionality, which I thought would be basic, involves coming to Forge to get a plugin and there's never ANY documentation. It's basically just "Hey... here's a plugin" without even a paragraph on how to use it.We're all simply left to just... guess.

Solution

I just tried it, I was easily able to. I am quite new to Out systems too.


Here is a screenshot. Its quite easy actually.



Please share oml in case you need more help ( Also be sure your oml does not contain confidential logic you wrote ) . Community can help you out for most issues. we in community are quite active here.

Solution

Hi Brian,

After going through your description I understand that you are a having sever action to create or update Todo record .inside this server action you want to get the location latitude and longitude values using location plugin. If I am not wrong

Here there is a simple basic thing inside sever action you cannot use the client action. So it's the reason you cannot find the location plugin scope inside server action. Try to pass the latitude and longitude values as an input parameters to the server action where you want to create or update Todo record

Hope this will helps you

Regards,

Koushik


This worked. In my problem I talked about using it in a server action. I forgot to mention I tried client actions too and had no luck. No where in the expression editor would the Location/GetLocation items show up when working with expressions in client side actions. No widgets were available. The only way to do this when the client action is open is to go into the Logic tab, and then navigate to Client Actions->LocationPlugin and then drag the GetLocation object onto the screen from there. This is the only way it was available. 


You would think once I added a reference to the project that it would show up in the expression editor or as a widget  like all the other dependencies that I reference. For some reason, this plugin does not do that. Dragging it from the logic tab appears to be the only way you can work with it. Thanks.


coder kamath wrote:

I just tried it, I was easily able to. I am quite new to Out systems too.


Here is a screenshot. Its quite easy actually.



Please share oml in case you need more help ( Also be sure your oml does not contain confidential logic you wrote ) . Community can help you out for most issues. we in community are quite active here.



In theory everything should be working, but the value of the lat/lng doesn't seem to be getting saved.

I dropped the Getlocation icon into my client side save-click event. In my CreateOrUpdateToDoWrapper I added a Location input param and passed it GetLocaton.Location

Inside my server side function I assign my ToDo.Lat and ToDo.Lng to the location's latitude and longitude properties. It doesn't seem that the value is actually being stored after I build, refresh the app, and save. I look at the database and 0's are being stored as the values (for what it's worth I DID get prompted at one point to access my devices's location when I was running the emulated app inside my Android Outsystems app).

On debugging, the GetLocation gives the error "cordova is not defined". Keep in mind I'm debugging on a browser and not a mobile device so I'm not sure if there is something not available when debugging. Although, my computer should have location services as with HTML5 I'm able to grab my lat/lng very easily with Javascript.


Put a Break-point on Assign statement, Go into Debugging mode and see what values you are getting near the Assign Statement

coder kamath wrote:

Put a Break-point on Assign statement, Go into Debugging mode and see what values you are getting near the Assign Statement

Sorry, I edited my comment above. I did do debugging. I set a breakpoint on the action right AFTER i dropped the GetLocation into the path. The GetLocation action's success=false and the error is "Cordova is not defined:.


Granted this is on a Browser, so I'm not even sure if this is something I *can* debug, but in Windows 10, my Location Service is on and I've had no problem with html/javascript web applications getting my lat/lng from this PC


Try to take a look at these ongoing Discussions.

https://www.outsystems.com/forge/component-discussions/1395/Location+Plugin.


Many seem to have similar issues and have got it solved as well.


Some times solved on its own, due to GPS non availability. And some have used Location-change trigger to find out whats going on.


PC Browsers  don't use GPS so they work differently Internally I guess


Also if possible please share oml, I can try to see from my end to See if there is anything I can help.


Also I would suggest to seach within the forum about the Cordova error

Take a look at this


https://www.outsystems.com/forums/discussion/37703/mobile-notification-using-onesignal-error-message-cordova-is-not-defined/


Many are saying if you build the Actual App and try it, It will work fine for the cordova error

I finally got it working.

I added a new field to my Core and Local ToDo entities called "GPS error". Since I can't debug on mobile, I figured I would take any error messages and pass them to the wrapper server and save them to the ToDo record so I could debug old-fashioned style (spitting error messages to alerts or DB values). 

I got "Timeout expired". Odd. No other application I use has had trouble "connecting" to my GPS.  So I changed the Timeout and MaximumAge values to 60,000 "60 seconds".. The form obviously took about 60 seconds to save and again... Timeout Expired.


I fired up Uber just as a "second opinion" and it was telling me that it was having trouble locating me and recommended me to switch to "high accuracy mode", which I did. Then it worked... I got my coordinates.

Weird. And now that I think about it, I *have* had some issues with GPS lately. DirecTV Now requires GPS to be enabled. I'll turn on my GPS and I'll notice that my location defaults to "Phone Only". Apparently, this isn't enough sometimes on my Android. I don't know if "Phone only" is just a bad setting or if I have some kind of damage to my GPS. Or maybe it's because when I use my GPS I'm usually in my home or office. When I'm using Uber, I'm generally on the sidewalk outside. 


Either way.. hopefully this "debugging on phone" workaround helps someone else. Lesson Learned: If things aren't working on mobile and you can't debug... pass various possible error messages into your DB records and see if anything shows up.

Thanks for the help




coder kamath wrote:

Try to take a look at these ongoing Discussions.

https://www.outsystems.com/forge/component-discussions/1395/Location+Plugin.


Many seem to have similar issues and have got it solved as well.


Some times solved on its own, due to GPS non availability. And some have used Location-change trigger to find out whats going on.


PC Browsers  don't use GPS so they work differently Internally I guess


Also if possible please share oml, I can try to see from my end to See if there is anything I can help.


Also I would suggest to seach within the forum about the Cordova error




Raghuram Kamath escribió: Hi, check it out, you do not have a .oml that you can share, please, I'd really appreciate it. =D

Acabo de probarlo, fácilmente pude. Soy bastante nuevo en los sistemas de salida también.


Aquí hay una captura de pantalla. Es bastante fácil en realidad.



Comparta oml en caso de que necesite más ayuda (también asegúrese de que su oml no contenga la lógica confidencial que escribió). La comunidad puede ayudarte en la mayoría de los problemas. Nosotros en comunidad somos bastante activos aquí.