43 lines
1000 B
JavaScript
43 lines
1000 B
JavaScript
GMaps.geolocate = function(options) {
|
|
var complete_callback = options.always || options.complete;
|
|
|
|
if (navigator.geolocation) {
|
|
navigator.geolocation.getCurrentPosition(function(position) {
|
|
options.success(position);
|
|
|
|
if (complete_callback) {
|
|
complete_callback();
|
|
}
|
|
}, function(error) {
|
|
options.error(error);
|
|
|
|
if (complete_callback) {
|
|
complete_callback();
|
|
}
|
|
}, options.options);
|
|
}
|
|
else {
|
|
options.not_supported();
|
|
|
|
if (complete_callback) {
|
|
complete_callback();
|
|
}
|
|
}
|
|
};
|
|
|
|
GMaps.geocode = function(options) {
|
|
this.geocoder = new google.maps.Geocoder();
|
|
var callback = options.callback;
|
|
if (options.hasOwnProperty('lat') && options.hasOwnProperty('lng')) {
|
|
options.latLng = new google.maps.LatLng(options.lat, options.lng);
|
|
}
|
|
|
|
delete options.lat;
|
|
delete options.lng;
|
|
delete options.callback;
|
|
|
|
this.geocoder.geocode(options, function(results, status) {
|
|
callback(results, status);
|
|
});
|
|
};
|