Я рассмотрел несколько подобных проблем GPS. Но, похоже, не было большой удачи. Когда я вытаскиваю GPS по этому методу - он, кажется, тянет старые данные, т. Е. От последнего GPS-сигнала. Какие-либо предложения?GPS Pull - выталкивает старые данные за несколько раз до обновления до текущего местоположения
Это простое приложение для GPS-навигации javascript, которое заполняет форму при запросе.
<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()"/> <input type="submit" value="Add GPS"></td>
</tr>
</table>
<input type="hidden" name="src" value="gpsup">
</cfform>
Так ваш вопрос: «Почему« watchPosition »не постоянно обновляется?» –
Да, я думаю, или я должен использовать что-то другое? Для получения правильной позиции потребуется несколько выдержек - иногда около 5 или более. –
Я пытаюсь: меняя watchPosition на getCurrentPosition - согласно http://dev.w3.org/geo/api/spec-source.html - это одноразовая GPS-тяга - я буду тестировать еще –