test geolocation

Change class name on click in jQuery

by jpeter06

HTML

<div >
  <button> dosomething</button>
  <textarea id="ta" rows="4" cols="50"></textarea>
</div>

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

JavaScript

var id, target, options,ta;
ta=document.getElementById('ta');

function success(pos) {
  var crd = pos.coords;
	ta.value+='\n'+crd.latitude+' '+crd.longitude;
  if (target.latitude === crd.latitude && target.longitude === crd.longitude) {
    console.log('Congratulations, you reached the target');
    navigator.geolocation.clearWatch(id);
  }
}

function error(err) {
  console.warn('ERROR(' + err.code + '): ' + err.message);
}

target = {
  latitude : 0,
  longitude: 0
};

options = {
  enableHighAccuracy: false,
  timeout: 5000,
  maximumAge: 0
};

id = navigator.geolocation.watchPosition(success, error, options);