0
我正在嘗試創建geoJson對象,用於在地圖上顯示帶有mapbox.js和flickr-api的flickr圖像。在for循環中創建GeoJSON
我不能設法得到正確的格式莫名其妙,各種引號缺失,任何人都可以幫忙嗎?我已經發布了我需要在下面創建的JSON循環和類型。
var data = [];
window.jsonFlickrApi = function(rsp) {
var photos = rsp.photos.photo;
for (var i = 0; i < photos.length; i++) {
var p = photos[i];
var url = [ 'http://farm', p.farm, '.static.flickr.com/', p.server, '/', p.id, '_', p.secret, '_s.jpg' ].join('');
data.push({"geometry":{
"type": "Point",
"coordinates": [p.latitude, p.longitude]},
"properties":{
"url": url,
"image": url,
"name":p.title,
"description": "something"}
});
}
}
console.debug(data);
這是我想創建JSON類型:
{ "type": "feature collection",
"features":[
{
"geometry": { "type": "Point", "coordinates": [5.123699,52.071039]},
"properties": {
"image": "https://lh4.googleusercontent.com/-YDA7Borc-K8/S2vU_zk9GKI/AAAAAAAAAQ0/4rn5myADmdE/s912/pavello.jpg",
"url": "http://timcastelijn.nl",
"name": "pavello",
"description": "paviljoentje voor hergebruik",
}
}, {
"geometry": { "type": "Point", "coordinates": [5.117997,52.085776]},
"properties": {
"image": "http://farm9.staticflickr.com/8363/8376204495_61d75a7f10.jpg",
"url": "http://timcastelijn.nl",
"name": "hout en bank",
"description": "houten bedframe en puntgave tweezitter",
}
}, {
"geometry": { "type": "Point", "coordinates": [5.08, 52.08]},
"properties": {
"image": "http://1.bp.blogspot.com/_aq9-5vIIz5s/TNbBtAJLaJI/AAAAAAAAANs/92_6emkfm8s/s1600/hout.jpg",
"url": "http://timcastelijn.nl",
"name": "boomstammen",
"description": "30 stammetjes van ca 1m lang",
}
}, {
"geometry": { "type": "Point", "coordinates": [5.12, 52.11]},
"properties": {
"image": "http://www.deouderust.nl/wp-content/uploads/2011/09/kast-%E2%82%AC2200-.jpg",
"url": "http://timcastelijn.nl",
"name": "oude kast",
"description": "kast, uit hardhout onderdelen",
}
}]
}