Geolocation in a form

goingtocry 21 Oct, 2012
Hi guys.

Thanks for replying to all my past questions.

I have an insteresting script I would like to include in Chronoforms V4, I have tried, but I have a problem with the Javascipt site of things. It works perfectly if I create a separate html file and use cellphone browsing - But I need to get it into a form and as soon as the user logs in i receive their co-ordinates, rate per hour - Its used for a employee time tracking for field services.



<!DOCTYPE html> 
<html>  
  <head>
    <title>LAT LONG TEST</title>
    <script src="http://www.google.com/jsapi"></script>
    <script>
      google.load("jquery", "1.4.1");
    </script>
  </head>
  <body>
    <form action="upload.html" method="get">
     
      <div>
        <input type="text" id="lat_field" name="latitude" />
        <input type="text" id="long_field" name="longitude" />
      </div>
      <script>
        navigator.geolocation.getCurrentPosition(
          function(pos) {
            $("#lat_field").val(pos.coords.latitude);
            $("#long_field").val(pos.coords.longitude);
          }
        );
      </script>
   
    </form>
  </body>
</html> 


Thanks guys
GreyHead 21 Oct, 2012
Hi goingtocry,

You should be able to call the API with just this code in a Load JS action

window.addEvent('domready', function() {
  navigator.geolocation.getCurrentPosition( function(pos) {
    $('lat_field').value  = pos.coords.latitude;
    $('long_field').value = pos.coords.longitude;
  });
});
I've translated the snippet into MooTools so you no longer need the JQuery load.

Bob
This topic is locked and no more replies can be posted.