ФRuŠKać

Geolocation

constructor
Geolocation()

Option name Type Description
Initial Array

data array

function Geolocation() {

    var self = this;

    var enabled,
        interval;

    // Try HTML5 geolocation.
    if (navigator.geolocation) {

        self.marker = new google.maps.Marker({
            icon: {
                path: google.maps.SymbolPath.CIRCLE,
                fillColor: '#d2003b',
                fillOpacity: 1.0,
                strokeColor: '#d2003b',
                strokeOpacity: .5,
                strokeWeight: 3,
                scale: 6
            }
        });

        self.marker.setMap(gmap);

        update();

        interval = setInterval(function () {
            update();
        }, 5000);

    } else {
        console.warn('Browser doesn\'t support Geolocation');
    }

update

function
update()

Get user's location

function update() {
    navigator.geolocation.getCurrentPosition(function (position) {

        var LatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
        self.marker.setPosition(LatLng);

        if (!enabled) {
            util.show(document.getElementById('map_button_locate'));
            enabled = true;
        }

    }, function () {
        console.warn('Browser location not available');
        clearInterval(interval);
    });
}

    }

Geolocation

prototype
Geolocation.prototype

Geolocation.prototype = {

locate

method
Geolocation.prototype.locate()

Center map on user's location

locate: function () {
    gmap.setCenter(this.marker.position);
    gmap.setZoom(16);
}

    };

    window.locate = function () {
geolocation.locate()
    };

    return Geolocation;

})();