我尝试存储一个数组中的纬度和经度,该数组的长度有时为1,有时为2或3。
代码如下:
var latitude,longitude;
$.each(data.results, function (i, item) {
var name = item.from_user;
var img = item.profile_image_url;
var text=item.text;
var profile_img=item.profile_image_url;
var url=(item.entities.urls.length > 0 ? item.entities.urls[0].url : '');
Placemaker.getPlaces(text,function(o){
console.log(o);
if (typeof(o.match!=='undefined') ||(o.length==1)){
latitude=o.match.place.centroid.latitude, longitude=o.match.place.centroid.longitude;
console.log(latitude,longitude);}
else if (typeof(o.match[0]!=='undefined') ||(o.match.length==2)){
latitude=o.match[0].place.centroid.latitude, longitude=o.match[0].place.centroid.longitude;
console.log(latitude,longitude);
}
});
array.push({name:name,img:img,text:text,latitude:latitude,longitude:longitude,profile_img:profile_img,url:url});
从这段代码中,当数组长度为1时,我只得到纬度和经度值,所以只执行第一个if。我正在尝试修复其他数组,以便也可以从其他数组中获取值,因为当我使用console.log输出数组时,纬度和经度的值都不在那里。我猜在将所有值放入数组之前,循环必须先获取所有值。
我正在尝试通过推文位置输出谷歌地图上的推文。我没有使用地理编码,但雅虎placemaker从推文的文本地理定位的位置。
下面是placemaker数组结构http://www.flickr.com/photos/codepo8/3553188917/的快照
这是尝试获取值对象{ match=2}的另一个数组
发布于 2012-08-12 19:04:42
typeof(o.match!=='undefined')
总是“布尔型”的,我想你想要typeof(o.match)!=='undefined'
或者仅仅是typeof o.match!=='undefined'
https://stackoverflow.com/questions/11924487
复制相似问题