-
1 Aug 2012 5:42 AM #1
Unanswered: TypeError: 'undefined' is not an object only when building
Unanswered: TypeError: 'undefined' is not an object only when building
I have some code that I am trying to get working to show a map and where you are and places close by and other things like that. However, it works fine when I test it out using localhost, but when trying to build the app using package, production, or testing, I receive the error:
Code:[INFO] Resolving your application dependencies (...) [ERROR] TypeError: 'undefined' is not an object Stack trace: ...
It seems like something is wrong with the "navigator.geolocation.getCurrentPosition" line or the useCurrentLocation line, because when I comment that line out, everything is fine. Or, if I leave the line uncommented, and change useCurrentLocation to true, it also builds okay. Either way, the application does not output an errors in Google Chrome's console when running.Code:Ext.define("LocationTwo.view.Main",{ extend: 'Ext.Container', requires: [ 'Ext.Map' ], config: { layout: 'vbox', items: [ { xtype: 'map', useCurrentLocation: false, flex: 1, listeners: { maprender: function( mapComponent, mapObject, options ) { console.log( 'maprender' ); var create = function( position ) { }; var error = function( errorInfo ) { }; var options = { enableHighAccuracy: true }; navigator.geolocation.getCurrentPosition( create, error, options ); } } } ] } });
-
2 Aug 2012 6:45 AM #2
Also note that this works:
Main.js:
MapView.js:Code:Ext.define( 'LocationTwo.view.Main',{ extend: 'Ext.Container', requires: [ 'LocationTwo.view.MapView' ], config: { layout: 'card', items: [ { xtype: 'button', text: 'Click me', listeners: { tap: function( button ) { button.up( 'container' ).setActiveItem( { xtype: 'mapview' } ); } } } ] } });
But if you were change Main.js to this:Code:Ext.define( 'LocationTwo.view.MapView',{ extend: 'Ext.Map', xtype: 'mapview', config: { useCurrentLocation: false, listeners: { maprender: function() { navigator.geolocation.getCurrentPosition( this.createMap, this.onError, { enableHighAccuracy: true } ); } } }, createMap: function( position ) { }, onError: function( errorInfo ) { } });
the application won't build, despite the fact that it results in the same program on screen before building the application.Code:Ext.define( 'LocationTwo.view.Main',{ extend: 'Ext.Container', config: { layout: 'card', listeners: { initialize: function( button ) { this.setActiveItem( { xtype: 'mapview' } ); } } } });
-
3 Aug 2012 5:02 AM #3Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
- Answers
- 3156
Why are you using a listener to add items? Also you aren't requiring the map view in this code:
Could be:Code:Ext.define( 'LocationTwo.view.Main',{ extend: 'Ext.Container', config: { layout: 'card', listeners: { initialize: function( button ) { this.setActiveItem( { xtype: 'mapview' } ); } } } });
Code:Ext.define('LocationTwo.view.Main', { extend : 'Ext.Container', xtype : 'locationtwo-main', //<debug> requires: [ 'LocationTwo.view.MapView' ], //</debug> config : { layout : 'card', items : [ { xtype : 'mapview' } ] } });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
7 Aug 2012 5:33 AM #4
I think I didn't require the map view because it was included in the views: [ ] in the app.js file. Also, using the listener to add the map view was just something that I was trying differently to get it to work. I was wondering why you could add the view using a button okay but not using a listener. Doing it normally with the items config still doesn't work.
Main.js:
MapView.js:Code:Ext.define( 'LocationTwo.view.Main',{ extend: 'Ext.Container', requires: [ 'LocationTwo.view.MapView' ], config: { layout: 'fit', items: [ { xtype: 'mapview' } ] } });
Again, it's only the packaging fails using "sencha app build [package|production|testing]". It works fine when running it from localhost, which is the part that I find puzzling.Code:Ext.define( 'LocationTwo.view.MapView',{ extend: 'Ext.Map', xtype: 'mapview', config: { useCurrentLocation: false, listeners: { //Error still occurs if this is initialize rather than maprender maprender: function() { navigator.geolocation.getCurrentPosition( function( position ) { }, function( error ) { }, { enableHighAccuracy: true } ); } } } });
-
30 Aug 2012 2:31 PM #5
Had same error
Had same error
after that type error do you get a stack trace and then another error like this?
the first error distracted me from the bottom url error. I entered the url into my browser and I got a javascript error in the console and that's the problem that really needed solving. I was testing up until then with foo.com/?foo=bar but the error was citing just foo.com. It had been a while since I tested without the query param and didn't realize I had an error in there. Hopefully your problem is as simple as mine.Code:[ERROR] Failed loading your application from: <url>
-
30 Aug 2012 2:38 PM #6
Well, navigator might not be defined in that context.
Did you try to use things like this:
if(navigator && navigator.geolocation && navigator.geolocation.getCurrentPosition)
{
navigator.geolocation.getCurrentPosiotion( someHandler );
}


Reply With Quote