4 <meta http-equiv=
"content-type" content=
"text/html; charset=UTF-8" />
5 <title>Show Geolocation on page load
</title>
8 function triggerGeo(onSuccess
, onError
) {
9 if (navigator
.geolocation
) {
10 navigator
.geolocation
.getCurrentPosition(onSuccess
, onError
);
12 document
.getElementById('lat').innerHTML
=
13 'Error: navigator.geolocation is false';
14 document
.getElementById('lng').innerHTML
= '';
19 function triggerGeoWithCallback(callback
){
20 triggerGeo(function (position
){
22 }, function(positionError
){
27 function showPosition(position
) {
28 var lat
= position
.coords
.latitude
;
29 var lng
= position
.coords
.longitude
;
30 document
.getElementById('lat').innerHTML
= lat
;
31 document
.getElementById('lng').innerHTML
= lng
;
34 function showError(positionError
) {
35 document
.getElementById('lat').innerHTML
=
36 positionError
.message
;
37 document
.getElementById('lng').innerHTML
= '';
43 <body onload=
"triggerGeo(showPosition, showError)">
44 <b id=lat
>-
1</b>,
<b id=lng
>-
1</b>