我正在尝试创建geoJson对象,用于使用mapbox.js和 flickr-api 在地图上显示 flickr 图像。
我无法以某种方式获得正确的格式,缺少各种引号,有人可以帮忙吗?我已经在下面发布了我需要创建的循环和 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",
}
}]
}