Skip to content

Instantly share code, notes, and snippets.

@chasestarr
Created February 28, 2016 04:28
Show Gist options
  • Save chasestarr/905c8fe10825ab2c45a9 to your computer and use it in GitHub Desktop.
Save chasestarr/905c8fe10825ab2c45a9 to your computer and use it in GitHub Desktop.
var searchYelp = function(params, callback){
yelp.search(params, function(e,res){
// console.log(res);
if(e) return console.log(e);
var center = [res.region.center.latitude, res.region.center.longitude];
//Map api response to format readable by mapbox
var businessData = res.businesses.map(function(element){
var coordObj = element.location.coordinate;
var output = readDB(element.id, function(tableStatus){
var obj = {
type: "Feature",
geometry:{
type: "Point",
coordinates: [coordObj.longitude,coordObj.latitude]
},
properties:{
title: element.name,
url: element.url,
address: element.location.address[0],
rating: starRating(element.rating),
host: tableStatus,
id: element.id,
"marker-color": "#fc4353",
"marker-size": "small"
}
};
return obj;
});
return output;
});
//package data to not repeat center obj
var geoObj = {
center: center,
geoJSON: businessData
}
callback(geoObj);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment