cho45 (owner)

Revisions

gist: 228509 Download_button fork
public
Public Clone URL: git://gist.github.com/228509.git
Embed All Files: show embed
location.js #
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
49
50
51
52
53
54
55
56
function getCurrentLocationMapLink (callback) {
    getCurrentLocation(function (pos) {
        var lat = pos.coords.latitude;
        var lon = pos.coords.longitude;
        var q = lat + ',+' + lon;
        var uri = 'http://maps.google.co.jp/maps?q=' + q + '&iwloc=A&hl=ja';
        callback(uri);
    });
}
 
function getCurrentLocation (callback) {
    var geo = navigator.geolocation || google.gears.factory.create('beta.geolocation');
    var dialog = createElementFromString(
        ['<div class="overlay">',
            '<div class="content">',
                '<span class="message">GPS Fixing...</span><input type="button" value="Cancel" class="cancel"/>',
             '</div>',
         '</div>'].join(''), {
            parent: document.body
        }
    );
 
    dialog.setAttribute('style', 'color: #fff; background: #000; opacity: 0.9; position: absolute; top: 0; left: 0;');
    dialog.style.height = (document.documentElement.scrollHeight) + 'px';
    dialog.style.width = (document.documentElement.scrollWidth) + 'px';
 
    dialog.content.setAttribute('style', 'position: absolute; text-align: center; vertical-align: 50%; width: 100%;');
    dialog.content.style.lineHeight = (window.innerHeight) + 'px';
    dialog.content.style.top = (window.pageYOffset) + 'px';
 
    document.body.style.overflow = 'hidden';
 
    var id = geo.watchPosition(
        function (pos) {
            geo.clearWatch(id);
            callback(pos);
            dialog.parentNode.removeChild(dialog);
        },
        function (e) {
        },
        {
            enableHighAccuracy: true,
            maximumAge: 0,
            gearsLocationProviderUrls: []
        }
    );
 
    dialog.cancel.addEventListener('click', function (e) {
        document.body.style.overflow = 'visible';
        geo.clearWatch(id);
        dialog.parentNode.removeChild(dialog);
    }, false);
 
    dialog.cancel.focus();
}