0

I am using the Formidable Pro Wordpress plugin and I am trying to figure how to achieve the following:

I need the users gps location in two form fields when a check box is clicked. I have two scripts and have no idea how to combine them.

First gets the location:

var x=document.getElementById(“demo”);
    function getLocation()
    {
    if (navigator.geolocation)
    {
    navigator.geolocation.watchPosition(showPosition);
    }
    else{x.innerHTML=”Geolocation is not supported by this browser.”;}
    }
    function showPosition(position)
    {
    x.innerHTML=”Latitude: ” + position.coords.latitude +
    “<br>Longitude: ” + position.coords.longitude;
    }

Next is one that I was told to use to change the value of the fields:

jQuery(document).ready(function($){
  $('input[name="item_meta[30]"]').change(function(){
    $('select[name="item_meta[31]"], select[name="item_meta[32]"]').val('');
  })
})

I tried this with no luck, as I have no idea what I am doing...

jQuery(document).ready(function($){
$('input[name="item_meta[29]"]').change(function(){
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(change);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}{
$('input[name="item_meta[30]"]').val(position.coords.latitude);})
$('input[name="item_meta[31]"]').val(position.coords.longitude);})
})

Any help is much appreciated!

2
Contributors
1
Reply
11
Views
3 Years
Discussion Span
Last Post by radhakrishna.p
0

hi Douglas_2,
if you want to place the coordinate values in two fields then try to change the code in the showPosition() method is enough.
i mean change like from this to (instead of displaying into div)

 x.innerHTML=”Latitude: ” + position.coords.latitude +“<br>Longitude: ” + position.coords.longitude;

this

document.getElementById('field1').value = position.coords.latitude;
document.getElementById('field2').value = position.coords.longitude;

if you have fields like this in your form
<input type="text" id="field1">
<input type="text" id="field2">

try to do like as shown above you will get output as you like

let me know the status

note: any comments are appreciated.

Edited by radhakrishna.p: better understanding

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.