Hi all,<div><br></div><div>I've tweaked the script a little and added the markers layer in advance of the jquery function. It's beginning to dawn on me that what's going on is that the jquery fired portion of the script isn't accessing some of the OL functions, and is passing null data, or that's the closest to a reasonable solution I can think of...</div>
<div>The error I'm getting now is "<span class="objectBox objectBox-errorMessage hasBreakSwitch "><span class="errorMessage ">c.getCode is not a function" reference to OL line 311.</span></span></div><div><span class="objectBox objectBox-errorMessage hasBreakSwitch "><span class="errorMessage "></span></span>Any ideas?<br>
<br><div class="gmail_quote">On Sun, Jun 5, 2011 at 8:29 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;">
Hi all,<div><br></div><div>I've hacked together a geolocation script using the OpenLayers demo, a tutorial on Mobile Tutorials <a href="http://mobile.tutsplus.com/tutorials/mobile-web-apps/html5-geolocation/" target="_blank">http://mobile.tutsplus.com/tutorials/mobile-web-apps/html5-geolocation/</a>, and a couple of other OL-Geolocation demos out there. Independently, I've gotten the parts of the script to work, but I'm not sure what's happening here when bring them all togehter and use jquery for my button firing. </div>
<div><br></div><div>The script calls the initGIS function onLoad loading a simple map set to a lonlat. The button then fires the geolocation script, which uses modernizr to check for geoloc support, provides error checking and olderbrowser support via YQL (maybe I should use the MIT-license geo.js? suggestions). The script was breaking on adding the markers, but I realized that I had to declare some of the variables as globals. The issue now is a rather opaque error in the OL code saying "<span style="color:rgb(255, 0, 0);font-family:Consolas, 'Lucida Console', monospace;font-size:12px;line-height:12px;white-space:pre-wrap">Uncaught TypeError: Object function (){var a=null;if(this.baseLayer!=null)a=this.baseLayer.projection;return a} has no method 'getCode'"</span></div>
<div><span style="color:rgb(255, 0, 0);font-family:Consolas, 'Lucida Console', monospace;font-size:12px;line-height:12px;white-space:pre-wrap"><br></span></div><div><span style="font-size:12px;line-height:12px;white-space:pre-wrap"><font face="arial, helvetica, sans-serif">Firefox returns the following error.</font></span></div>
<div><span style="color:rgb(255, 0, 0);font-family:Consolas, 'Lucida Console', monospace;font-size:12px;line-height:12px;white-space:pre-wrap"><br></span></div><div><span style="color:rgb(255, 0, 0);font-family:Consolas, 'Lucida Console', monospace;font-size:12px;line-height:12px;white-space:pre-wrap">attempt to run compile-and-go script on a cleared scope</span></div>
<div><span style="color:rgb(255, 0, 0);font-family:Consolas, 'Lucida Console', monospace;font-size:12px;line-height:12px;white-space:pre-wrap"><br></span></div><div><font face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:12px;white-space:pre-wrap">The chrome error says the script breaks at OL line 311, while FF says that the script is breaking at OL 256. This is above my programming experience, and I'm not sure how to resolve this error.</span></font></div>
<div><font face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:12px;white-space:pre-wrap"><br></span></font></div><div><font face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:12px;white-space:pre-wrap">code is as follows with the error checking functions cut off the end of it.</span></font></div>
<div><font face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:12px;white-space:pre-wrap"><br></span></font></div><div><font face="arial, helvetica, sans-serif"><span style="font-size:12px;line-height:12px;white-space:pre-wrap"><div>
var markers = new OpenLayers.Layer.Markers("Markers");</div><div>var map = new OpenLayers.Map('map');</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);<span style="white-space:pre-wrap">        </span></div><div>map.setCenter(new OpenLayers.LonLat(-90, 38).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject()),12);</div>
<div>}</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(showMap,handle_error);</div>
<div>} else {</div><div>yqlgeo.get('visitor',norm_yql_resp);</div><div>}</div><div>}</div><div><br></div><div><br></div><div>function showMap(position)</div><div>{</div><div>//alert('Lat: ' + position.coords.latitude + ' ' + 'Lon: ' + position.coords.longitude + ' ' + 'Acc: ' + position.coords.accuracy);</div>
<div>var lonlat = new OpenLayers.LonLat(position.coords.longitude,position.coords.latitude).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject);</div><div>markers.addMarker(new OpenLayers.Marker(lonlat));</div>
<div>map.setCenter(new OpenLayers.LonLat(lonlat, 12));</div><div>map.addLayer(markers);</div><div>}</div><div>}</div><div></script></div><div></body></div><div></html></div></span></font></div>
</blockquote></div><br></div>