var utils = {};

utils.getCurrentLocation = function() {
    var dfd = $.Deferred();

    if(!navigator.geolocation) {
	alert('Geolocation API is unavalable.');
	dfd.reject();
    }

    navigator.geolocation.getCurrentPosition(function(position) {
	var location = {"latitude" : position.coords.latitude,
			"longitude": position.coords.longitude};
	dfd.resolve(location);
    }, function(error) {
	alert('ERROR(' + error.code + '): ' + error.message);
	dfd.reject();
    });

    return dfd.promise();
};

utils.fetchPosts = function(options) {
    var dfd = $.Deferred();

    var api_uri = 'http://amateras.wsd.kutc.kansai-u.ac.jp/~otsuka/michishiki_api_server/select.py';
    var query_string = utils.optionsToQueryString(options);
    $.getJSON(api_uri + query_string, function(json) {
	dfd.resolve(json);
    });

    return dfd.promise();
};

utils.optionsToQueryString = function(options) {
    var querys = [];
    for (var key in options) {
	var q = key + '=' + options[key];
	querys.push(q);
    }
    return '?' + querys.join('&');
};

utils.utcToString = function(utc_ms) {
    var date_obj = new Date(utc_ms);
    var year = date_obj.getFullYear();
    var month = date_obj.getMonth()+1;
    var date = date_obj.getDate();
    var day = ['日', '月', '火', '水', '木', '金', '土'][date_obj.getDay()];
    var hour = date_obj.getHours();
    var minute = date_obj.getMinutes();
    if (month < 10) month = "0" + month;
    if (date < 10) date = "0" + date;
    if (hour < 10) hour = "0" + hour;
    if (minute < 10) minute = "0" + minute;

    var date_str = year + '/' +
	    month + '/' +
	    date + '(' + day + ') ' +
	    hour + ':' + minute;

    return date_str;
};
@@ -1037,24 +1037,783 @@
 n('&');%0A%7D;%0A%0A
+utils.QueryStringBuilder = function() %7B%0A    this.options = %7B%7D;%0A%7D;%0A%0Autils.QueryStringBuilder.prototype.setRegion = function(lat1, lng1, lat2, lng2) %7B%0A    this.options%5B'lat1'%5D = lat1;%0A    this.options%5B'lng1'%5D = lng1;%0A    this.options%5B'lat2'%5D = lat2;%0A    this.options%5B'lng2'%5D = lng2;%0A%7D;%0A%0Autils.QueryStringBuilder.prototype.setOrderBy = function(order_by, order) %7B%0A    this.options%5B'order_by'%5D = order_by;%0A    this.options%5B'order'%5D = order;%0A%7D;%0A%0Autils.QueryStringBuilder.prototype.setLimit = function(limit) %7B%0A    this.options%5B'limit'%5D = limit;%0A%7D;%0A%0Autils.QueryStringBuilder.prototype.build = function() %7B%0A    var querys = %5B%5D;%0A    for (var key in this.options) %7B%0A%09var q = key + '=' + this.options%5Bkey%5D;%0A%09querys.push(q);%0A    %7D%0A    return '?' + querys.join('&');%0A%7D;%0A%0A
 utils.utcToS

Implement query string builder to construct conditions when fetching posts