Hi all,<div><br></div><div>I&#39;ve tweaked the script a little and added the markers layer in advance of the jquery function. It&#39;s beginning to dawn on me that what&#39;s going on is that the jquery fired portion of the script isn&#39;t accessing some of the OL functions, and is passing null data, or that&#39;s the closest to a reasonable solution I can think of...</div>
<div>The error I&#39;m getting now is &quot;<span class="objectBox objectBox-errorMessage hasBreakSwitch "><span class="errorMessage ">c.getCode is not a function&quot; 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">&lt;<a href="mailto:n.e.kendall@gmail.com">n.e.kendall@gmail.com</a>&gt;</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&#39;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&#39;ve gotten the parts of the script to work, but I&#39;m not sure what&#39;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 &quot;<span style="color:rgb(255, 0, 0);font-family:Consolas, &#39;Lucida Console&#39;, 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 &#39;getCode&#39;&quot;</span></div>

<div><span style="color:rgb(255, 0, 0);font-family:Consolas, &#39;Lucida Console&#39;, 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, &#39;Lucida Console&#39;, 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, &#39;Lucida Console&#39;, 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, &#39;Lucida Console&#39;, 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&#39;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(&quot;Markers&quot;);</div><div>var map = new OpenLayers.Map(&#39;map&#39;);</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(&quot;EPSG:4326&quot;),map.getProjectionObject()),12);</div>

<div>}</div><div><br></div><div>jQuery(window).ready(function(){jQuery(&quot;#btnInit&quot;).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(&#39;visitor&#39;,norm_yql_resp);</div><div>}</div><div>}</div><div><br></div><div><br></div><div>function showMap(position)</div><div>{</div><div>//alert(&#39;Lat: &#39; + position.coords.latitude + &#39; &#39; + &#39;Lon: &#39; + position.coords.longitude + &#39; &#39; + &#39;Acc: &#39; + position.coords.accuracy);</div>

<div>var lonlat = new OpenLayers.LonLat(position.coords.longitude,position.coords.latitude).transform(new OpenLayers.Projection(&quot;EPSG:4326&quot;), 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>&lt;/script&gt;</div><div>&lt;/body&gt;</div><div>&lt;/html&gt;</div></span></font></div>
</blockquote></div><br></div>