Hi everyone,<div><br></div><div>I apologize in advance for what is probably a simple fix and spaghetti code, but I'm starting to get bug eyed here. I'm trying to grab near-by tweets using jquery getJSON. I had this working to where the script was showing my new tweet locations, but somewhere in the last few iterations my code started adding the 'tweetz' layer as undefined (it's labeled 'undefined in the layer switcher. I've run the code through jslint and firebug, and there weren't obvious errors. Thanks again, I've stripped the code of my comments and white space.</div>
<div><br></div><div>Code below:</div><div><div>var feat, OpenLayers, latlon, selectedFeature, selectControl, selectedFeature;</div><div>var tweetz = new OpenLayers.Layer.Vector("Tweets", {styleMap: new OpenLayers.StyleMap({externalGraphic: "js/OpenLayers-2.11-rc1/img/marker-green.png", pointRadius: 10})});</div>
<div>var marker = new OpenLayers.Layer.Vector("Marker", {styleMap: new OpenLayers.StyleMap({externalGraphic: "js/OpenLayers-2.11-rc1/img/marker.png", pointRadius: 10})});</div><div>var map = new OpenLayers.Map('map_tweet');</div>
<div>var tweets = [];</div><div>var tweetsQ = [];</div><div>var refreshQuery = '?=';</div><div><br></div><div>function init_tweet(){</div><div>map.addControl(new OpenLayers.Control.LayerSwitcher());</div><div>var mapnik = new OpenLayers.Layer.OSM();</div>
<div>map.addLayer(mapnik);</div><div>var tweetz = new OpenLayers.Layer.Vector();</div><div>map.addLayer(tweetz);</div><div>map.setCenter(new OpenLayers.LonLat(-90, 38).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject()),12);</div>
<div>$(document).everyTime('30s', acquireTweets);</div><div>$(document).everyTime('100ms', parseTweetsQ);</div><div>getLoc();</div><div>} </div><div><br></div><div><br></div><div>//jQuery(window).ready(function(){jQuery("#btnInit").click(getLoc);});</div>
<div>function getLoc(){</div><div>if (Modernizr.geolocation) {</div><div> navigator.geolocation.getCurrentPosition(plotLoc,handle_error);</div><div>} else {</div><div>yqlgeo.get('visitor',norm_yql_resp);</div><div>
}</div><div>}</div><div><br></div><div>function createTWTsrcURL (){</div><div>var temp = map.getCenter().transform(new OpenLayers.Projection("EPSG:900913"),new OpenLayers.Projection("EPSG:4326"));</div>
<div>return '<a href="http://search.twitter.com/search.json">http://search.twitter.com/search.json</a>' + refreshQuery + '&geocode=' + temp.lat +'%2C' + temp.lon + '%2C50km&rpp=100&callback=?';</div>
<div>}</div><div><br></div><div>function plotLoc (position){</div><div>map.addLayer(marker);</div><div>var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(position.coords.longitude,position.coords.latitude).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject()),11);</div>
<div>marker.addFeatures([feat]);</div><div>var bounds = marker.getDataExtent();</div><div>map.setCenter(bounds.getCenterLonLat(),10);</div><div><br></div><div>acquireTweets();</div><div>}</div><div><br></div><div><br></div>
<div><br></div><div>function acquireTweets(){</div><div>$.getJSON(createTWTsrcURL(), function(data){</div><div>if(data.results)</div><div>$.each(data.results, function(i, tweet){</div><div>if (tweet.geo || tweet.location)</div>
<div>tweetsQ.push(tweet);</div><div><br></div><div>});</div><div>refreshQuery = data.refresh_url;</div><div>});</div><div>}</div><div><br></div><div>function parseTweetsQ(){</div><div>if (tweetsQ.length > 0) {</div><div>
var tweet = tweetsQ.pop();</div><div>if (tweet.geo){</div><div>var lon = tweet.geo.coordinates[1];</div><div>var lat = tweet.geo.coordinates[0];</div><div>tweet.point = new OpenLayers.Geometry.Point(lon,lat).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());</div>
<div>plotTwt(tweet);}}}</div><div><br></div><div><br></div><div>function plotTwt(tweet){</div><div>var twtfeat = new OpenLayers.Feature.Vector(tweet.point);</div><div>tweetz.addFeatures(twtfeat);</div><div>}</div><div>function handle_error(error) {</div>
<div>switch(error.code){case error.PERMISSION_DENIED: alert("This application reguires you to agree to share your location. Please reload the page to see it work properly. There is a privacy disclaimer at the bottom of this page. This site does not currently record or store these data, and in the future will not record unique user information without informing the user or asking their permission. -Virtual Spatiality");</div>
<div>break;case error.POSITION_UNAVAILABLE: alert("could not determine position");</div><div>break;case error.TIMEOUT: alert("timeout retrieving position");</div><div>break;default: alert("unknown error");</div>
<div>break;}}</div><div>function norm_yql_resp(response){if (response.error) {var error = {code : 0};handle_error(error);return;}var position = {coords:{latitude: response.place.centroid.latitude,longitude: response.place.centroid.longitude},address :{city: response.place.locality2.content,region: response.place.admin1.content,country: response.place.country.content}};handle_geolocation_query(position);}</div>
</div>