Jump to content

Html Block - To Detect Geo Location


Recommended Posts

Hi Support team

 

I created a table and this table records will be created by user when the run a Form.

 

In this form, I try records user GEO location.  I attached a HTML Block into the form.  Please see the code :

 

Once user to execute this form and click submit, user GEO location will be updated into the table by field Latitude and Longitude.  

 

I have tried so many time, but stiff not successful to update this two field.  Can you please help to check what is the missing, please?

 

Regards

Patrick Li

 

-------------------------------------------------

</div>
<script>
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(GEOprocess, GEOdeclined);
} else{
  document.getElementById('geo').innerHTML = 'Your browser do not support geo-location.';
}
 
// called when the browser has shown support of navigator.geolocation
 
function GEOprocess(position) {
gLongitude = position.coords.longitude;
  gLatitude = position.coords.latitude;
  console.log('latitude: ' + gLatitude + ' ; longititude: ' + gLongitude);
 
// update the page to show we have the lat and long
  //document.getElementById('geo').innerHTML = 'Latitude: ' + position.coords.latitude + ' Longitude: ' +        position.coords.longitude;
 
     document.write(document.getElementbyId('geo')(position.coords.latitude([@field:Latitude])))
 
</script>
----------------------------------------------------------------------------------------
 
 
Link to comment
Share on other sites

  • 2 weeks later...

Hello Patrick,

 

So you need to get user's geo position and put it to the hidden field on the form?

 

Insert this code in to the footer of your DataPage (it's better to past JS code in to the Footer, when you work with data on the form, because content of the HTML block can be loaded before the form was fully loaded):

<script type='text/javascript'>
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(GEOprocess, GEOdeclined);
} else{
  document.getElementById('InsertRecordGEO').value = 'Your browser do not support geo-location.';
}
 
// called when the browser has shown support of navigator.geolocation
 
function GEOprocess(position) {
gLongitude = position.coords.longitude;
  gLatitude = position.coords.latitude;
  console.log('latitude: ' + gLatitude + ' ; longititude: ' + gLongitude);
 
// update the page to show we have the lat and long
  document.getElementById('InsertRecordGEO').value = 'Latitude: ' + position.coords.latitude + ' Longitude: ' +        position.coords.longitude;
 
 }
 function GEOdeclined() {
 document.getElementById('InsertRecordGEO').value = 'Your browser do not support geo-location.';
 }
</script>

And replace GEO with your field's name.

 

P.S. Field names will be different on the different form types. As example, on the Submission form you should use InsertRecordYOURFIELDNAME, on the Update form it will be EditRecordYOURFIELDNAME.

 

Let me know if this helps.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...