summaryrefslogtreecommitdiffstats
path: root/chrome/test/data/geolocation/geolocation_on_load.html
blob: 69b0bb54a1d1a7ec43f3b0e58f786af0f2995586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>Show Geolocation on page load</title>
    <script>

function triggerGeo(onSuccess, onError) {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(onSuccess, onError); 
  } else {
    document.getElementById('lat').innerHTML =
        'Error: navigator.geolocation is false';
    document.getElementById('lng').innerHTML = '';
  }
}


function triggerGeoWithCallback(callback){
  triggerGeo(function (position){
    callback("allow");
  }, function(positionError){
    callback("block");
  });
}

function showPosition(position) {
  var lat = position.coords.latitude;
  var lng = position.coords.longitude;
  document.getElementById('lat').innerHTML = lat;
  document.getElementById('lng').innerHTML = lng;
}

function showError(positionError) {
  document.getElementById('lat').innerHTML =
      positionError.message;
  document.getElementById('lng').innerHTML = '';
}

    </script>
  </head>

<body onload="triggerGeo(showPosition, showError)">
<b id=lat>-1</b>, <b id=lng>-1</b>
</body>

</html>