• 0
Login to follow this  
Hearnie

Geo Coordinates From Phone

Question

Does anybody have some code that can stamp the geolocation of a mobile device into a data form when that form is viewed.

 

I am looking at a way that when a record is updated it automatically grabs the geo coordinates from the device that viewed it and stamps them into the record from.

 

Any ideas greatly appreciated

 

Hearnie

Share this post


Link to post
Share on other sites

10 answers to this question

  • 0

Many thanks

I am indeed looking for a way to stamp coordinates from a device when a data page is viewed

I hope there may be some Java out there that can grab the phone GPS lat and long and then stamp it into a data table

Steve

Share this post


Link to post
Share on other sites
  • 0

You could try something along the lines of the following, your browser may prompt you to allow current location.  

 

<script type="text/javascript">
     function initGeolocation()
     {
        if(navigator.geolocation)
        {
           // Call getCurrentPosition with success
           navigator.geolocation.getCurrentPosition(success);
        }
        else
        {
           alert("Sorry, your browser does not support geolocation services.");
        }
     }

     function success(position)
     {
//Change to InsertRecord for a submission form

//Current_Long and Current_Lat should change to reference correct field names
         document.getElementById("EditRecordCurrent_Long").value = position.coords.longitude;
         document.getElementById("EditRecordCurrent_Lat").value = position.coords.latitude
     }

//Modify behavior for method trigger as desired
window.onload = initGeolocation();
 </script>   
 

Share this post


Link to post
Share on other sites
  • 0

Many thanks Caspio Ninja

 

At the risk of sounding a total novice, what would I need to put in the form submission field in my caspio app to receive the location parameters.

 

I have no problem with the warning notification as I will also be stamping the IP address.  

 

So, how do I get the Lat and Long above into my data page?

 

Thanks so much

 

Steve

Share this post


Link to post
Share on other sites
  • 0

You would need 2 fields to capture the latitude and longitude, in the example above the fields Current_Long and Current_Lat were used.  These fields need to be included on the submission form, but can be hidden fields.  For a submission form as well, any spots in the script using EditRecord need to change to InsertRecord.

Share this post


Link to post
Share on other sites
  • 0

The script above would write the longitude and latitude to fields named Current_Long and Current_Lat. As long as you have these fields on your datapage as hidden with no default value and the script above is in your footer it should work.

Share this post


Link to post
Share on other sites
  • 0

New note on this script: You may see an error if the DataPage is deployed on a page using http.  Please see this message:

 

getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.

Share this post


Link to post
Share on other sites
  • 0

Thanks GoCubbies for the heads up about this code not working on an insecure server anymore.  I was testing out a new app using one of my update record forms which contains this code and I thought I "broke" the page because it wasnt capturing the Lat & Long anymore on Chrome.  I direct users now the https Caspio page directly instead of my URL and it works!  The only drawback is that the browser now prompts you to accept sharing your location from Caspio rather than your own URL! 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Login to follow this