0

I reviewed a few GPS problems similar. But seemed to not have much luck. When I pull GPS by this method - it seems to pull old data, ie where last GPS pull was from. Any suggestions?

This is a simple javascript GPS pull - that populates the form when the requested.

 <script type="text/javascript"> 

function getLocationConstant()
{
    if(navigator.geolocation)
    {
        watchID = navigator.geolocation.watchPosition(onGeoSuccess,onGeoError); 
    } else {
        alert("Your browser or device doesn't support Geolocation");
    }
}

// Get a single location update
function getLocationConstant()
{
    if(navigator.geolocation)
    {
        navigator.geolocation.getCurrentPosition(onGeoSuccess,onGeoError);
    } else {
        alert("Your browser or device doesn't support Geolocation");
    }
}

// If we have a successful location update
function onGeoSuccess(event)
{
    document.getElementById("Latitude").value =  event.coords.latitude; 
    document.getElementById("Longitude").value = event.coords.longitude;

}

// If something has gone wrong with the geolocation request
function onGeoError(event)
{
    alert("Error code " + event.code + ". " + event.message);
}
 </script>

 <div class=general align=center>
 <cfform action="gps_pull.cfm" method="post">
 <div align=center>
 <b>GPS Services Needs to be enabled on your device.</b>
 <br>
 <br>With a GPS Capable Device - Choose "Get Location". Once the GPS data is pulled in, choose "Add GPS".
 <br><span class=code8>You may need to allow GPS Device time to pull current location</span>
 </div>
 <br>
 <table align=center>
 <tr>
 <td>Latitude:</td>
 <td><cfinput type="text" id="Latitude" name="gpslat" value="" required="yes" message="Choose Get Location First"></td>
 </tr>
 <tr>
 <td>Longitude:</td>
 <td><cfinput type="text" id="Longitude" name="gpslong" value=""></td>
 </tr>
 <tr>
 <td colspan=2 align=center><br><input type="button" value="Get Location" onclick="getLocationConstant()"/> &nbsp; <input type="submit" value="Add GPS"></td>
 </tr>
 </table>
 <input type="hidden" name="src" value="gpsup">
 </cfform>
Andrew Leach
  • 12,945
  • 1
  • 40
  • 47
Merle_the_Pearl
  • 1,391
  • 3
  • 18
  • 25
  • So is your question "Why does `watchPosition` not continually update?" – Andrew Leach May 22 '12 at 06:34
  • Yeah I guess, or should I be using something different? It will take several pulls to get the right position - sometimes about 5 or more. – Merle_the_Pearl May 22 '12 at 12:46
  • I'm trying this: changing watchPosition to getCurrentPosition - according to http://dev.w3.org/geo/api/spec-source.html - it is a one time GPS pull - I'll test some more – Merle_the_Pearl May 22 '12 at 15:50

2 Answers2

0

watchPosition can take options: watchPosition(onGeoSuccess,onGeoError,options); and the default values are

options = { "enableHighAccuracy": false,
            "timeout"           : Infinity,
            "maximumAge"        : 0 }

It may be that your GPS device doesn't record small changes in position unless enableHighAccuracy is true. When it notices the position change, onGeoSuccess is called again. And you can force the position to be found again by recreating the watch (but the position held by the GPS may not have changed because of the enableHighAccuracy setting).

enableHighAccuracy is also applicable to getCurrentPosition options, and will work in the same way.

Andrew Leach
  • 12,945
  • 1
  • 40
  • 47
  • Trying now - had the max age added - and removed the watch position stuff - just trying with getCurrentPosition - thx for insight so far – Merle_the_Pearl May 22 '12 at 21:41
0

This is what I have the code down too. Still pulls old data, usually take 3+ pulls to get correct data. Using Android Samsung Galaxy S2 - have tried with GPS mode only and GPS + Cell Triangulation. And still takes 3+ pulls usually to get right data.

Ideas folks?

 <script type="text/javascript"> 

// Get a single location update
function getLocationConstant()
{
    if(navigator.geolocation)
    {
        navigator.geolocation.getCurrentPosition(onGeoSuccess,onGeoError,{enableHighAccuracy:true,maximumAge:0});
    } else {
        alert("Your browser or device doesn't support Geolocation");
    }
}

// If we have a successful location update
function onGeoSuccess(event)
{
    document.getElementById("Latitude").value =  event.coords.latitude; 
    document.getElementById("Longitude").value = event.coords.longitude;

}

// If something has gone wrong with the geolocation request
function onGeoError(event)
{
    alert("Error code " + event.code + ". " + event.message);
}
 </script>
Merle_the_Pearl
  • 1,391
  • 3
  • 18
  • 25