For the last two weeks, I have attempted to get my current location and the location coordinates from my app, so that I can use them for API call’s…etc. Currently it is not possible to get the coordinates, nor does the platform allow for location usage. I have scoured your documentation also, and there is nothing in Google, YouTube or your forum regarding location.
Since your program is not capable of this, would it be possible to get a download of my code and then issue a refund? My entire app is based on location and not being able to use it has put us at a stand still.
Do you have the latest Kodika version?
You can get the current Location using the Locations Plugin in our Code Blocks.
You can use these blocks
were you able to get your current location using the above code blocks?
Yes, I am aware of those settings, but they do not work. No matter what function order you choose, there is no prompting for permissions, on either the simulator or a real device. Additionally, its not possible to extract the specifics latitude and longitude in number format. I need to get the coordinates so that I can create API calls. Do you know when this feature will be updated to work properly?
I could be doing something wrong, but there is zero documentation on this feature, which is very surprising, as it is used in almost all apps now a days.
You are right about the documentation and we will try to update it. In the meantime you can follow these steps to make it work.
You need to:
- request Permissions
- Add a Listener for position updates
- Start Listening for the position updates
The use the Location Listener, you will need to implement a function called
You can find it by pressing the
Location Manager Protocol on the Left of the Screen after you create your Request Location Permission Function.
After you add the
didUpdateLocation: function, if you open it you will see that it has a parameter called
You can use this
location parameter to get the latest fetched location
Call Request Location permission
Do not forget to call the first
Request Location Permission from a button or when a screen loads.
OK, I will try this tomorrow once my app stop crashing.
Thank you again for this example, but this is not working still. It is not retrieving the location and the latitude and longitude are blank. I have tried it on the simulator and device and still does not work.
It looks like it doesn’t update the variables as the API is running to soon before the location, but I moved the function around and now it works.
Yeah. You can use the Code Blocks from the
Datasource or the
API category and start the Datasource or API request only after you have received the latest location.
I have done that, but it causes my screen to flicker and jump. Not sure how to get around this, so right now location isnt’ working.
didUpdateLocations: is an asynchronous function so it will not be called immediately after you call the
Start Location Updates. For that reason you will need to start your
execute api request inside the
didUpdateLocations: and after you have set the API params using the Location.
Could you please send me an example of your function when the screen flickers or a video of the screen flickering? Maybe it has to do with something else and not with the location.
Ok, so the first screenshot is my function that is going to get the api call and use the lat/lon parameters like you showed. When I move this function into didUpdateLocations, the screen flickers, because once the API call completes, its runs a navigation to a new screen, but because the phone is physically moving, the api call/navigation runs multiple times, and the screen jumps…as its being navigated to several times.
I moved the navigation out didUpdateLocations, but now the API call doesn’t work because, as you said, I don’t have the lat/lon due to async. I am not sure how to make it wait. Also, I know I can do, stop location updates, but that also doesn’t fire in time.
I may have to rethink the whole app now
I see the problem.
What you can do is have a Bool as Screen Property and update it from inside the
So the first time that you get a new Location you will set that property to
Then you can have an if in the didUpdateLocation and check the value of the Screen Property and do not run the Screen Navigation after the first time.
So the first time that you will get a Location you will call your api request, but not the second.
So move back the execute in
didUpdateLocation but add everything in an if.
I can send you an example if you want.
I think I understand what you are asking, but could you send an example?
What I suggest is to keep the Function that requests Locations as you have it
and then in
didUpdateLocations: to check if you have got any location, and if not(false), then do the API Request. Note that I change the bool to true, so for the next location it will not step into the if and will ignore the location so you will not have duplicate calls to API and flicker on screen.
Thank you, this makes sense. So didUpdateLocation won’t fire unless there is a location? It looks like the executeapi request is running every time the function is running? Do i make it false to start?
didUpdateLocation fires every time there is a new location. if for example you are underground, it will not fire.
ExecuteApi request is runs every time you call it. If you put it in the If and then immediatelly change the value to true, it will run only once. You will need to set it to false and wait for a new location to fire the API again.
There is no need to set it to false to start, as every bool starts as false, but you can do it if you want.
It looks like its below the IF statement, that is my question. Should it not be in the DO part?
Yeah, you are right. my bad. The api should be in the DO.
Ok, I will set it up that way? And I assume this will only cause DO to run once?