8
8

More than 5 years have passed since last update.

GPSデータの取得

Last updated at Posted at 2012-06-08

window.onload = function(){
    navigator.geolocation.watchPosition(update); //現在位置情報を定期的に監視

    // navigator.geolocation.getCurrentPosition(); //現在位置情報を取得
    // navigator.geolocation.clearWatch(); //watchPosition()での監視を中止
}

function update(position){
    //下記すべての情報が取得できるわけでは無い
    var lat = position.coords.latitude; //緯度
    var lng = position.coords.longitude; //経度
    var alt = position.coords.altiude; //高度
    var acc = position.coords.accuracy; //緯度経度の誤差
    var alc = position.coords.altiudeAccuracy; //高度の誤差
    var hed = position.coords.heading; //方角
    var spe = position.coords.speed; //スピード

    var txt  = "緯度:" + lat + "<br>";
        txt += "経度:" + lng + "<br>";
        txt += "高度:" + alt + "<br>";
        txt += "緯度経度誤差:" + acc + "<br>";
        txt += "高度誤差:" + alc + "<br>";
        txt += "方角:" + hed + "<br>";
        txt += "速度:" + spe + "<br>";    
    console.log(txt);
}

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8