Exemplo n.º 1
0
        Place.findById(idPlace, function(err,result){
            //console.log(result);

            parameters = {
                location:[result.Location.lat, result.Location.lng],
                name: result.Name
            };
            console.log(parameters);
            googlePlaces.placeSearch(parameters, function (response) {
                console.log(response);
                if (response.status === "OK"){
                    googlePlaces.placeDetailsRequest({reference:response.results[0].reference}, function (response) {
                        console.log(response.result);
                        if (response.result.opening_hours){
                            if (response.result.opening_hours.periods) {
                                var horarios = response.result.opening_hours.periods;
                                var horarios_count = horarios.length;
                                var horarios_formated = ["Closed today", "Closed today", "Closed today", "Closed today", "Closed today", "Closed today", "Closed today"];
                                for (var i = 0; i < horarios_count; i++) {
                                    if (horarios[i].open && horarios[i].close) {
                                        if (horarios_formated[horarios[i].open.day] === "Closed today") {
                                            horarios_formated[horarios[i].open.day] = [horarios[i].open.time.slice(0, 2), ":", horarios[i].open.time.slice(2)].join('') + "-" +
                                                [horarios[i].close.time.slice(0, 2), ":", horarios[i].close.time.slice(2)].join('');
                                        } else {
                                            horarios_formated[horarios[i].open.day] = horarios_formated[horarios[i].open.day] + " " + [horarios[i].open.time.slice(0, 2), ":", horarios[i].open.time.slice(2)].join('') +
                                                "-" +
                                                [horarios[i].close.time.slice(0, 2), ":", horarios[i].close.time.slice(2)].join('');
                                        }
                                    }else if (horarios[i].open){
                                        if (horarios_formated[horarios[i].open.day] === "Closed today") {
                                            horarios_formated[horarios[i].open.day] = [horarios[i].open.time.slice(0, 2), ":", horarios[i].open.time.slice(2)].join('');
                                        } else {
                                            horarios_formated[horarios[i].open.day] = horarios_formated[horarios[i].open.day] + " " + [horarios[i].open.time.slice(0, 2), ":", horarios[i].open.time.slice(2)].join('');
                                        }
                                    }
                                }
                                result.opening_hours = horarios_formated;
                            }
                        }

                        if (response.result.url){
                            result.url = response.result.url
                        }else if (response.result.website){
                            result.url = response.result.website
                        }
                        result.reviews = response.result.reviews;
                        result.photos = response.result.photos;
                        cb(err,result);
                    });
                }else{
                    cb(err,result);
                }
            });
        });
Exemplo n.º 2
0
function getGooglePlaces(request, reply) {

    var currentLatitude = request.query.latitude;
    var currentLongitude = request.query.longitude;

    parameters = {
    	location: [request.query.latitude, request.query.longitude],
    	types: request.query.type
    };

    googlePlaces.placeSearch(parameters, function(error, places_response) {

        if (error) {
            throw error;
        }

        var places = places_response.results;
        console.log(JSON.stringify(places, null, 2));

        var arr = new Array();

        async.each(places, function(place, callback) {

            var location = {
                latitude: place.geometry.location.lat,
                longitude: place.geometry.location.lng
            };

            var diff = distance(currentLatitude, currentLongitude, 
                location.latitude, location.longitude, 'K');

            var splits = place.vicinity.split(', ');
            var city = splits[splits.length - 1];

            var data = {
                place_id: place.place_id,
                name: place.name,
                icon: place.icon,
                location: location,
                distance: {
                    "unit": "km",
                    "value": diff.toFixed(2)
                },
                address: {
                    city: city
                }
            };
            arr.push(data);
        });

        reply(arr);
    });
}
var config = require("./config.js");

var GooglePlaces = require("googleplaces");
var googlePlaces = new GooglePlaces(config.apiKey, config.outputFormat);
var parameters;

/**
 * Place search - https://developers.google.com/places/documentation/#PlaceSearchRequests
 */
parameters = {
  location:[-33.8670522, 151.1957362],
  types:"doctor"
};
googlePlaces.placeSearch(parameters, function (response) {
  console.log(response.results);
});
Exemplo n.º 4
0
// Callback function that appends data from Google Places API
function addGoogleData(restaurant, lat, lon) {
	restaurant["open"] = [];
	restaurant["close"] = [];
	restaurant["mealType"] = [];

	var parameters = {
		location: [lat, lon],
		types: "restaurant"
	};

	googlePlaces.placeSearch(parameters, function (error, response) {
		if (error) throw error;
		var results = response["results"];
		if (results.length > 0) {
			googlePlaces.placeDetailsRequest({reference: results[0]["reference"]}, function (error, response) {
				if (error) throw error;
				if (response.result.hasOwnProperty("opening_hours") && response.result["opening_hours"].hasOwnProperty("periods") && response.result["opening_hours"]["periods"].length > 0) {
					var times = response.result["opening_hours"]["periods"];
					var opens = [];
					var closes = [];

					// Add opening and closing times for each day of the week if available
					for (var i = 0; i < 7; i++) {
						if (times[i]) {
							var openingTime = null;
							var closingTime = null;
							if (times[i].hasOwnProperty("open")) {
								openingTime = times[i].open["time"];
							}
							if (times[i].hasOwnProperty("close")) {
								closingTime = times[i].close["time"];
							}
							opens.push(openingTime);
							if (closingTime) {
								closes.push(closingTime);
							}
						}
					}

					restaurant["open"] = opens;
					restaurant["close"] = closes;

					// Checks to set the correct mealType for each data point
					// We are just using the first available opening hour for the time being
					var time_open = opens[0];
					var time_close = closes[0];
					if (isBreakfast(time_open, time_close)) {
						restaurant["mealType"].push("breakfast");
					}
					if (isLunch(time_open, time_close)) {
						restaurant["mealType"].push("lunch");
					}
					if (isDinner(time_open, time_close)) {
						restaurant["mealType"].push("dinner");
					}
					if (isLateNight(time_open, time_close)) {
						restaurant["mealType"].push("latenight");
					}
				}
				appendJSONToFile(restaurant, "output.json");
			});
		}
	});
}
Exemplo n.º 5
0
module.exports.map_info = function (req, res, next) {
  googlePlaces.placeSearch(parameters, function (error, response) {
    if (error) throw error;
    res.send(response.results);
  });
}