Per a previous suggestion of Ian's the following seems to work and produces valid coordinates for both lat and lon<div><br></div><div>tweet.point = new OpenLayers.LonLat(tweet.geo.coordinates[0],tweet.geo.coordinates[1]).transform(new OpenLayers.Projection("EPSG:4326"),new OpenLayers.Projection("EPSG:900913"));</div>
<div><br></div><div>however, I still get the error at line 701 with "a.geometry.getBounds is not a function" in firebug. Chrome doesn't produce an error, but doesn't add the markers...<br><br><div class="gmail_quote">
On Tue, Jun 21, 2011 at 11:37 AM, Nicholas Efremov-Kendall <span dir="ltr"><<a href="mailto:n.e.kendall@gmail.com">n.e.kendall@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">Well, here's the kicker: </div><div><div class="im"><br><div>tweet.point = new OpenLayers.LonLat(tweet.geo.coordinates[0],tweet.geo.coordinates[1]).transform(new OpenLayers.Projection("EPSG:900913"),map.getProjectionObject());</div>
<div>this returns two valid coordinates</div></div><div>but with epsg 4326: the lat is corrupted to NAN.</div><div><br></div><div>This cycles through the tweets correctly, but appears to break in OL at line 701 with the error a.geometry.getBounds is not a function...which I assume has to do with why the markers don't get added to the map...</div>
<div><div></div><div class="h5">
<br><div class="gmail_quote">On Tue, Jun 21, 2011 at 11:10 AM, Nicholas Efremov-Kendall <span dir="ltr"><<a href="mailto:n.e.kendall@gmail.com" target="_blank">n.e.kendall@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Heath,<div>I believe I am calling the function on the LonLat pair with the below code</div><div><div><br></div><div>tweet.point = new OpenLayers.LonLat(tweet.geo.coordinates[0],tweet.geo.coordinates[1]).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());</div>
<div><br></div></div><div>which returns POINT(NaN Nan) when I call an alert in the below function. If I don't call the transform function on the point, which works by the way with placing the geolocated position which centers the map to get the 50km radius for the tweets. </div>
<div><br></div><div>I've tried your suggestion as well</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><div><div>var latlon = new OpenLayers.LonLat(tweet.geo.coordinates[0],tweet.geo.coordinates[1]);</div><div>latlon.transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());</div>
<div>tweet.point = latlon;</div>
</div><div>tweet.attributes = {};</div><div>plotTwt(tweet);</div><div>}}}</div><div><br></div></div><div><div>function plotTwt(tweet){</div><div>twtpoint = new OpenLayers.Geometry.Point(tweet.point);</div><div>alert(twtpoint);</div>
<div>twtmark = new OpenLayers.Features.Vector(twtpoint);</div><div>tweetz.addFeatures([twtmark]);</div><div>}</div></div><div><br></div><div>and I still get a POINT(Nan NaN) in the alert. I'm not sure what I'm doing wrong here, but the syntax follows from other examples, and I know I'm missing something really obvious here. If I call the alert in the parsetweet function, it appears that the lon is converted, but the lat is corrupted to a NaN...</div>
<div><br></div><div><div>function plotTwt(tweet){</div><div>twtpoint = new OpenLayers.Geometry.Point(tweet.point);</div><div>alert(twtpoint);</div><div>twtmark = new OpenLayers.Features.Vector(twtpoint);</div><div>tweetz.addFeatures([twtmark]);</div>
<div>alert(tweet.point);</div><div>}</div></div><div><br></div><div>Full code is below</div><div><br></div><div><div>var feat, OpenLayers, latlon;</div><div>var tweetz = new OpenLayers.Layer.Vector("Tweets", {styleMap: new OpenLayers.StyleMap({externalGraphic: "OpenLayers-2.11-rc1/img/marker-green.png", pointRadius: 10})});</div>
<div>var marker = new OpenLayers.Layer.Vector("Marker", {styleMap: new OpenLayers.StyleMap({externalGraphic: "OpenLayers-2.11-rc1/img/marker.png", pointRadius: 10})});</div><div>var map = new OpenLayers.Map('map');</div>
<div>var tweets = [];</div><div>var tweetsQ = [];</div><div>var refreshQuery = '?=';</div><div><br></div><div>function initGIS(){</div><div>map.addControl(new OpenLayers.Control.LayerSwitcher());</div><div>var mapnik = new OpenLayers.Layer.OSM();</div>
<div>map.addLayer(mapnik);</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><br></div><div><br></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><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" target="_blank">http://search.twitter.com/search.json</a>' + refreshQuery + '&geocode=' + temp.lat +'%2C' + temp.lon + '%2C50km&rpp=100&callback=?';}</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()));</div>
<div>marker.addFeatures([feat]);</div><div>var bounds = marker.getDataExtent();</div><div>map.zoomToExtent(bounds);</div><div>acquireTweets();}</div><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>});</div><div>refreshQuery = data.refresh_url;</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><div><div>tweet.point = new OpenLayers.LonLat(tweet.geo.coordinates[0],tweet.geo.coordinates[1]).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());</div>
</div><div>tweet.attributes = {};</div><div>plotTwt(tweet);</div><div>}}}</div><div><br></div><div>function createInfoContent(tweet) {</div><div>var retval = '';</div><div>retval += '<div class="tweet_info">';</div>
<div>retval += '<img alt="' + tweet.from_user_id + '" src="' +</div><div>tweet.profile_image_url + '" class="tweet_profile"/>';</div><div>retval += '<h3>' + tweet.from_user + '</h3>';</div>
<div>retval += '<p>' + tweet.text + '</p>';</div><div>retval += '<p>Source: <a href="' + tweet.source + '"/>' +</div><div>tweet.source + '</a></p>';</div>
<div>retval += '</div>';</div><div>return retval;}</div><div><br></div><div>function plotTwt(tweet){</div><div>twtpoint = new OpenLayers.Geometry.Point(tweet.point);</div><div>alert(twtpoint);</div><div>twtmark = new OpenLayers.Features.Vector(twtpoint);</div>
<div>tweetz.addFeatures([twtmark]);</div><div>alert(tweet.point);}</div><div><br></div><div><br></div><div>function handle_error(error) {</div><div>switch(error.code){</div><div>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;</div><div>case error.POSITION_UNAVAILABLE: alert("could not determine position");</div><div>break;</div><div>case error.TIMEOUT: alert("timeout retrieving position");</div><div>break;</div>
<div>default: alert("unknown error");</div><div>break;}}</div><div>function norm_yql_resp(response){</div><div><span style="white-space:pre-wrap">        </span>if (response.error) {</div><div><span style="white-space:pre-wrap">                </span>var error = {code : 0};</div>
<div><span style="white-space:pre-wrap">                </span>handle_error(error);</div><div><span style="white-space:pre-wrap">                </span>return;}var position = {coords:</div><div><span style="white-space:pre-wrap">                        </span>{<span style="white-space:pre-wrap">        </span>latitude: response.place.centroid.latitude,</div>
<div><span style="white-space:pre-wrap">                                </span>longitude: response.place.centroid.longitude</div><div><span style="white-space:pre-wrap">                        </span>},</div><div><span style="white-space:pre-wrap">                        </span>address :</div>
<div><span style="white-space:pre-wrap">                        </span>{city: response.place.locality2.content,</div><div><span style="white-space:pre-wrap">                                </span>region: response.place.admin1.content,</div>
<div><span style="white-space:pre-wrap">                                </span>country: response.place.country.content</div><div><span style="white-space:pre-wrap">                        </span>}};handle_geolocation_query(position);}</div><div><div></div><div>
<div class="gmail_quote">On Tue, Jun 21, 2011 at 10:44 AM, B. Heath Robinson <span dir="ltr"><<a href="mailto:heath@midnighthour.org" target="_blank">heath@midnighthour.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div>I should have proofread the email BEFORE I sent it.</div><div><br></div>Actually, it would be something like this:<div><br><div>var latlon = new OpenLayers.LonLat(tweet.geo.coordinates[0],tweet.geo.coordinates[1]);</div>
<div><div>latlon.transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());</div><div>tweet.point = latlon;</div><div><br></div></div><div>This assumes that tweet.geo.coordinates[0],tweet.geo.coordinates[1] is something that the LonLat constructor will take.</div>
<div><div></div><div><div><br><div><div>On Jun 21, 2011, at 10:39 AM, B. Heath Robinson wrote:</div><br><blockquote type="cite"><div style="word-wrap:break-word"><div>Transform operates on the coordinates, it does not return a new coordinates. You should use it like this:</div>
<div>var latlon = weet.geo.coordinates[0],tweet.geo.coordinates[1];</div><div>latlon.transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());</div></div></blockquote><blockquote type="cite">
<div style="word-wrap:break-word">
<div>tweet.point = latlon;</div><div><br></div><br><div><div>On Jun 21, 2011, at 10:21 AM, Nicholas Efremov-Kendall wrote:</div><br><blockquote type="cite">Hi guys thanks for the previous advice,<div><br></div><div>I'm still running into an issue, and I'm not sure how to resolve it. When I first use a OpenLayers.LonLat and transform the point, I get the lon converted correctect, but the lat is returned NaN. If I don't transform it, the coordinates remain correct.</div>
<div><br></div><div><div>tweet.point = new OpenLayers.LonLat(tweet.geo.coordinates[0],tweet.geo.coordinates[1]).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());</div><div><br></div><div>
I've been playing around with some different iterations, and I can get tweet.point to alert out with ever tweet that's pulled into the plotting function, but the markers aren't added. The issue seems to be with how I'm calling the transform function, because somehow after calling the function I get NaN's for the lat-lon's inside the point object. I'm really hitting a wall here.</div>
<div><br></div><div><div><br></div></div><div><br></div><div><div class="gmail_quote">On Tue, Jun 21, 2011 at 3:23 AM, Nick Kendall <span dir="ltr"><<a href="mailto:n.e.kendall@gmail.com" target="_blank">n.e.kendall@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF"><div>Thanks! Will take another crack at this Tom! <br><br>Sent from my mobile device</div><div><div></div><div><div><br>On Jun 21, 2011, at 2:37 AM, "Sveen Atle Frenvik (Geomatikk IKT)" <<a href="mailto:Atle.Frenvik.Sveen@geomatikk.no" target="_blank">Atle.Frenvik.Sveen@geomatikk.no</a>> wrote:<br>
<br></div><div></div><blockquote type="cite"><div>
try using an OpenLayers.Geometry.Point instead of an
OpenLayers.LonLat<br>
<br>
ie (untested, but i think this is rather correct):<br>
<br>
<div>function parseTweetsQ(){</div>
<div> if (tweetsQ.length > 0) {</div>
<div> var tweet = tweetsQ.pop();</div>
<div> if (tweet.geo){</div>
<div> tweet.point = new OpenLayers.Geometry.Point(tweet.geo.coordinates[0],tweet.geo.coordinates[1]).transform(new
OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());<br>
tweet.attributes = {}; //in this you coukd stuff
attributes of the tweet for easy access on clicks etc.<br>
</div>
<div> plotTwt(tweet);</div>
<div> }<br>
}<br>
}</div>
<div><br>
</div>
<div>
<div>function plotTwt(tweet){<br>
//why do you keep adding the layer for each tweet? <br>
</div>
<div> map.addLayer(tweetz);</div>
<div> tweet.marker = new OpenLayers.Feature.Vector(tweet.point,{attributes:{tweet.attributes]});</div>
<div> tweetz.addFeatures([tweet.marker]);<br>
}<br>
<br>
</div>
</div>
<br>
<br>
On 2011-06-21 05:00, Nicholas Efremov-Kendall wrote:
<blockquote type="cite">Hi Phil et al,
<div><br>
</div>
<div>Thanks for your response. The code as is does iterate through
the features as they are returned. I have a handle on it up to
the plotting function. An alert on the tweet.marker object
returns [object Object], while tweet.latlng returns readable
coordinates lon=38.6834,lat=-90.4313. I guess what I'm unsure
about is how to parse the object which is passed to the third
function. Thanks again.</div>
<div><br>
</div>
<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>});</div>
<div>refreshQuery = data.refresh_url;</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>tweet.latlng = new
OpenLayers.LonLat(tweet.geo.coordinates[0],tweet.geo.coordinates[1]);</div>
<div>plotTwt(tweet);</div>
<div>}}}</div>
<div><br>
</div>
<div>
<div>function plotTwt(tweet){</div>
<div>
map.addLayer(tweetz);</div>
<div>tweet.marker = new OpenLayers.Feature.Vector(new
OpenLayers.Geometry.Point(tweet.latlng).transform(new
OpenLayers.Projection("EPSG:4326"),map.getProjectionObject()));</div>
<div>tweetz.addFeatures([tweet.marker]);}</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<br>
<div class="gmail_quote">On Mon, Jun 20, 2011 at 9:13 PM, Phil
Scadden <span dir="ltr"><<a href="mailto:p.scadden@gns.cri.nz" target="_blank"></a><a href="mailto:p.scadden@gns.cri.nz" target="_blank">p.scadden@gns.cri.nz</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">I have no idea what the object returned
by twitter is but surely, but if<br>
you are using jsonp, then<br>
have in your code something like:<br>
jsonp_function(json)<br>
where jsonp_function is the name of jsonp callback and json
is the<br>
returned object. I would guess it contains an array of
feature type<br>
objects, so you would iterate through the array, creating
feature for<br>
each row, and calling vectorLayer.addFeatures(features) to
add them to<br>
the vector layer.<br>
<br>
Notice: This email and any attachments are confidential. If
received in error please destroy and immediately notify us.
Do not copy or disclose the contents.<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.osgeo.org" target="_blank"></a><a href="mailto:Users@lists.osgeo.org" target="_blank">Users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users" target="_blank"></a><a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a><br>
</blockquote>
</div>
<br>
</div>
<pre><fieldset></fieldset>
_______________________________________________
Users mailing list
<a href="mailto:Users@lists.osgeo.org" target="_blank"></a><a href="mailto:Users@lists.osgeo.org" target="_blank">Users@lists.osgeo.org</a>
<a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users" target="_blank"></a><a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a>
</pre>
</blockquote>
<br>
<br>
<pre cols="72">--
Atle Frenvik Sveen
Utvikler
Geomatikk IKT AS
tlf: 45 27 86 89
<a href="mailto:atle.frenvik.sveen@geomatikk.no" target="_blank"></a><a href="mailto:atle.frenvik.sveen@geomatikk.no" target="_blank">atle.frenvik.sveen@geomatikk.no</a></pre>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Users mailing list</span><br><span><a href="mailto:Users@lists.osgeo.org" target="_blank">Users@lists.osgeo.org</a></span><br>
<span><a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a></span><br></div></blockquote></div></div></div></blockquote></div><br>
</div>
</div>
_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.osgeo.org" target="_blank">Users@lists.osgeo.org</a><br><a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a><br>
</blockquote></div><br></div>_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.osgeo.org" target="_blank">Users@lists.osgeo.org</a><br><a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a><br>
</blockquote></div><br></div></div></div></div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div>