I am trying to store the latitude and the longitude from an array where its length is sometimes 1 ,sometimes 2 or 3 .
Here is the code:
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});
From this code I get only the latitude & longitude values when the array length is 1. So only the first if is executed. I am trying to fix the others so that I can get values from the other arrays as well, since when I use console.log to output the array, the values of latitude & longitude are not there. I guess that the loop has to finish getting all the values before putting them into the array.
I am trying to output the tweets on the google map via the tweets location. I am not using geocode but yahoo placemaker to geolocate the location from the text of the tweet.
here is a snapshot of the placemaker array structure http://www.flickr.com/photos/codepo8/3553188917/
this is the other array that am trying to get values Object { match=[2]}
typeof(o.match!=='undefined')is always “boolean”I think you want
typeof(o.match)!=='undefined'or justtypeof o.match!=='undefined'