Creating a nested array in javascript for a google map
I'm trying to generate a map of tradespeople nearby to the site visitor. I've figured out most of it and am stuck on the final part mainly due to my weakness when it comes to arrays, structures etc.
Apparently, the api needs an array that looks like:
var locations = [
['Bondi Beach', -33.890542, 151.274856, 4],
['Coogee Beach', -33.923036, 151.259052, 5],
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];
I'm adapting this for my application, i.e. not Australian beaches but company names.
function getNearbyTradies(oArg){
var lat = oArg.lat || "";
var lng = oArg.lng || "";
var tradies = [];
$.getJSON("cfcs/user.cfc?method=getNearbyUsers&returnformat=json&queryformat=column",{"lat":lat,"lng":lng},function(res,code){
if(res.ROWCOUNT > 0){
for (var i = 0; i<res.ROWCOUNT; i++) {
var company_name = res.DATA.COMPANY_NAME[i];
var lat = res.DATA.LAT[i];
var lng = res.DATA.LNG[i];
var trade_id = res.DATA.TRADIE_ID[i];
var oTradie = "['" + company_name + "'," + lat + "," + lng + "," + trade_id + "]";
//alert(oTradie); This gives ['Seal Plumbing',-36.9716195,174.8620086,121]
tradies.push(oTradie);
};
//alert(tradies[0]); This gives ['Seal Plumbing',-36.9716195,174.8620086,121]
};
});
};
Is there a better way than manually constructing the inner array like this? Also, I don't think this method adds the comma at the end of each nested array.
How can I view what the entire structure looks like to see if it conforms with the Aussie beaches template? I can only alert each inner array.
