[OpenLayers-Users] Re: help with geolocation/jquery/modernizr script: uncaught type error.

Nicholas Efremov-Kendall n.e.kendall at gmail.com
Sun Jun 5 10:29:32 EDT 2011


Hi all,

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...
The error I'm getting now is "c.getCode is not a function" reference to OL
line 311.
Any ideas?

On Sun, Jun 5, 2011 at 8:29 AM, Nicholas Efremov-Kendall <
n.e.kendall at gmail.com> wrote:

> Hi all,
>
> I've hacked together a geolocation script using the OpenLayers demo, a
> tutorial on Mobile Tutorials
> http://mobile.tutsplus.com/tutorials/mobile-web-apps/html5-geolocation/,
> 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.
>
> 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 "Uncaught TypeError: Object function (){var
> a=null;if(this.baseLayer!=null)a=this.baseLayer.projection;return a} has no
> method 'getCode'"
>
> Firefox returns the following error.
>
> attempt to run compile-and-go script on a cleared scope
>
> 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.
>
> code is as follows with the error checking functions cut off the end of it.
>
> var markers = new OpenLayers.Layer.Markers("Markers");
> var map = new OpenLayers.Map('map');
> function initGIS(){
> map.addControl(new OpenLayers.Control.LayerSwitcher());
> var mapnik = new OpenLayers.Layer.OSM();
> map.addLayer(mapnik);
> map.setCenter(new OpenLayers.LonLat(-90, 38).transform(new
> OpenLayers.Projection("EPSG:4326"),map.getProjectionObject()),12);
> }
>
> jQuery(window).ready(function(){jQuery("#btnInit").click(getLoc);});
> function getLoc(){
> if (Modernizr.geolocation) {
>  navigator.geolocation.getCurrentPosition(showMap,handle_error);
> } else {
> yqlgeo.get('visitor',norm_yql_resp);
> }
> }
>
>
> function showMap(position)
> {
> //alert('Lat: ' + position.coords.latitude + ' ' + 'Lon: ' +
> position.coords.longitude + ' ' + 'Acc: ' + position.coords.accuracy);
> var lonlat = new
> OpenLayers.LonLat(position.coords.longitude,position.coords.latitude).transform(new
> OpenLayers.Projection("EPSG:4326"), map.getProjectionObject);
> markers.addMarker(new OpenLayers.Marker(lonlat));
> map.setCenter(new OpenLayers.LonLat(lonlat, 12));
> map.addLayer(markers);
> }
> }
> </script>
> </body>
> </html>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110605/155a69cf/attachment.html


More information about the Users mailing list