Forum Discussion
Getting the current location will require some coding outside of native Quickbase. Your process would likely need to use a code page where the user clicks a button and navigates them to said codepage where you have some javascript that logs the date/time and their information. In that code you would have to use your browser or devices geolocation API or service to get the current position and then log it.
In this situation you can't use Pipelines because its independent of the user at that point, and unfortunately Quickbase doesn't have any native services specific to geolocation.
------------------------------
Chayce Duncan
------------------------------
I'm familiar with the method you outline. Kirk had his URL formula call a code page, which isn't working.
I use a code page that I found on the Magic Buttons app to capture the current time.
I also found code page that I can call from a button to open a popup window and then get the current lat/long. (attached), but I don't know how to get what I need from it. It works, but not on a mobile.
------------------------------
Barry Dolan
------------------------------
- ChayceDuncan2 years agoQrew Captain
At this point it would really just be trial and error with that code you linked above. That code is valid for modern browsers and should remain working on mobile, however you'll likely need to play around and attempt to tweak the response and display the full error string on screen so you can actually see what's going on.
Its possible that the configuration of the button as a pop up isn't working since its on a mobile device, or there might be something about your device settings that is blocking your device from responding to the geolocation API. Someone else on this forum might chime in later with existing code that you could copy, but best course now is just to play with that existing code and figure out what, if any errors are responding once you cross over to mobile.
------------------------------
Chayce Duncan
------------------------------- BarryDolan2 years agoQrew Cadet
The frustrating part is, I know it works, I just don't know how to pass the results back to form.
I can run the little popup and get the lat/long, so, in theory, I should be able to run some of that code to get the lat/long and pass it back to my fields.
Attached is the code that captures the coordinates to display on the popup.But then what???
------------------------------
Barry Dolan
------------------------------- ChayceDuncan2 years agoQrew Captain
Ah, well that is the easy part then. Once you have the results logged you would use the QB API to log it back to your record. Since your example says they're clocking in, then you'd be adding a record so you don't need anything like a Record ID parameter or anything. You can use either the HTTP API or the REST API, I've given an example of using the REST API below.
Using the REST api you need to get a temp token for the user logged in using a function like:
const tempToken = (dbid) => {return new Promise((resolve,reject) => {var headers = {'QB-Realm-Hostname': 'your realm','QB-App-Token': 'your app token','Content-Type': 'application/json'}fetch(`https://api.quickbase.com/v1/auth/temporary/${dbid}`,{method: 'GET',headers: headers,credentials: 'include'}).then(res => {if (res.ok) {return res.json().then(res => resolve(res.temporaryAuthorization));}return res.json().then(resBody => reject({status: res.status, ...resBody}));}).catch(err => reject(err))})}You also need an upsert function to load it to QB - something like:const upsert = (commit,token) => {return new Promise((resolve,reject) => {var headers = {'QB-Realm-Hostname': 'your realm','Authorization': `QB-TEMP-TOKEN ${token}`,'Content-Type': 'application/json'}var body = {to: dbid to load to,data: commit,}fetch('https://api.quickbase.com/v1/records',{method: 'POST',headers: headers,body: JSON.stringify(body)}).then(res => {if (res.ok) {return res.json().then(res => resolve(res));}return res.json().then(resBody => reject({status: res.status, ...resBody}));}).catch(err => reject(err))})}Put it all together in your code like:
function showPosition(position) {
tempToken(your dbid).then((token) => {
var commit = [
{
"fid of your latitude field": { value: position.coords.latitude },
"fid of your longitude field": { value: position.coords.longitude },
"fid of your date/time field": { value: code to get the date/time you want}
}
]
upsert(commit, token).then((res) => {
//handle the qb response here and redirect if successful
}).catch((err) => { // handle errors here })
})
}
Disclaimer is that you'll need to modify this code to fit your actual need and inject your own code to handle errors or any issues with syntax or formatting. It's hard to code directly into this interface so there might be syntax errors that would be easier to spot in a text editor.
------------------------------
Chayce Duncan
------------------------------
Related Content
- 4 months ago
- 3 months ago
- 4 months ago
- 10 months ago