How to pass two geolocation data
How to pass two geolocation data
gpontaro
Posts: 11Questions: 2Answers: 0
in DataTables
Hi
I have a table where i can edit some cells.
I have a script in php that calculate latitude and longitude and I would like to write this data in the database (not visible in the table) when editing of the row is finished.
How can I do this? Any suggestion?
Thanks
Gp
This discussion has been closed.
Answers
Sounds like a perfect use for server-side events. You can define a closure function that will set the values required.
See also this blog post for an overview of server-side events int he Editor libraries.
Allan
Hi
latitude and longitude are two fields in my DB that are not directly displayed in the table and this data is "calculated" each time the person update a row (a field) in the table with the editor. This table is for a mobile application that wants to get coordinates at each user update.
I can get latitude and longitude with html5 geolocalisation API (see http://www.w3schools.com/html/html5_geolocation.asp).
With a preEDIT or postEDIT trigger I can execute a function but I do not understand exactly the syntax or how ? Not sure that I can execute a JS ?
The JS for geolocalisation is something like this
How can integrate this in the process of table update ? Do you have any hints ?
thanks a lot
gp
Oh I see - you want to write the user's lat / long into the database from the geo location API? In that case I would suggest using two hidden fields in your Editor form (
hidden
) and simply set their values to be the position from the API:Allan
Hi Allan
I have some problems with setting this because of my "limitations in js".
I setup the following in .php file
and a js file gg.js that should get the actual position
then I included the JS in html file
but the variable latutude and longitude aren't available in when editing ?
Can you help me ?
I am missing something.
Thanks a lot
Best regards,
gp
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Hi
nobody can give me an advice?
I am blocked...
Thanks
What is
latitude
? Given that there is no variable symbol ($
) it must be a constant? Is that correct - it seems unlikely.I'm not sure I understand why you've used PHP events for this when I suggested Javascript events after the clarification on what the issue was?
What does your Editor Javascript initialisation look like?
Allan
Hi
I modified the files according to you last email.
php file
and the js file in this way
I get the latitude end longitude because in the js alert window (i forced) I can see them, but these variables are not passed to the DB. In fact the values in the DB does't change when I submit something new, moving myself in another location.
Any idea about the reason of that ?
thanks a lot
gp
When you submit the form, if you have a look in your browser's developer tools, specifically the Network tab, you'll see the Ajax request that was submitted. You'll also be able to see the data that was sent - what is that data? Does it include the lat / long? (we need to know that so we can narrow it down to a client-side or server-side issue).
Allan
Hi
I updated the field a_lettura and what I can see is that lat and lon fields are send out from client but the values are not updated.
Furthermore if I force a value for lat (123), I see that this value is not send out from client.
So it seems that editor.on is not "working" on client side ....
gp
I understand now - thanks. The issue is that
preSubmit
is triggered after the values have been read.You would need to do something like:
Allan
mmm
I tried (quick check) to fix data.lat and data.lon to a constant but nothing, these values are not passed to the db, I see that in the submission lat and lon values aren't changed.
now I do not understand if this problem could be caused from definition of lat and lon fields or there are some problems in the editor ...
in js
or
in php
gp
Does the loop execute correctly?
If you could give me a link to the page I could debug it directly.
Allan
Hi
I setup here a page http://pontarolo.ch/datatables/
As you can see the JS (presubmit part) has been set in the following way
best regs
gp
Sorry - this line:
Should have been:
There appears to be another issue as well - callback function given to
navigator.geolocation.getCurrentPosition
is asynchronous - i.e. it executes after the form has been submitted.Given that you only need to get the position of the client I would suggest that you should in fact run that function immediately on page start up and get the long / lat straight away. Then you can assign the values synchronously in the
preSubmit
event (i.e. without needing to get the position again).Allan
Hi
mmm, modifying lines like this I can get the coordinates in the tables if I edit twice the same line, see http://pontarolo.ch/datatables/
Is there not a way to force a double update in order to get coordinates inside ?
thanks
gp
No - all of Editor's events are synchronous. There is no way to pause their execution if you are using an asynchronous function.
Allan