Cross-platform SDK and HTML5 tools for mobile app development
X
 
5 posts / 0 new
Last post
aren372
aren372's picture
Offline
Mobile Conjurer
Joined: 28 Jul 2012
Posts:
how do location event listener

I want to determining location in my app, and I want do it in Screen rather than in moblet,

I saw tutorials below http://www.mosync.com/documentation/tutorials/determining-location

In this turorial, it mentioned ILocation, but only interface, no implementing,

should my moblet Inherit from ILocation and implement addLocationListener, removeLocationListener,informListeners myself? If so, how? Any complete example?

Thanks in advanced!

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:
Hmm, I've just checked to be

Hmm, I've just checked to be sure, and Screen does implement CustomEventListener.  Have you put

{syntaxhighlighter brush: cpp;fontsize: 100; first-line: 1; }void customEvent(const MAEvent& event);
{/syntaxhighlighter}

In your screen's .h file?

Ahh, I'll tell you what it might be, and that is adding itself as a custom event listener.

In your .h add

{syntaxhighlighter brush: cpp;fontsize: 100; first-line: 1; }void show();{/syntaxhighlighter}

and in the cpp add

{syntaxhighlighter brush: cpp;fontsize: 100; first-line: 1; }void MyScreen::show()
{
Environment::getEnvironment().addCustomEventListener(this);
Screen::show();
}{/syntaxhighlighter}

 

 

aren372
aren372's picture
Offline
Mobile Conjurer
Joined: 28 Jul 2012
Posts:
Thanks,sam. addCustomEventLis

Thanks,sam.

addCustomEventListener in show() function doesn't work for me.

Maybe because my screen is one tab of TabScreen, I don't need to call show() function to show it.

After put it out of this Screen class, it works perfect! 

Here's my code:

TabScreen tabScreen = new TabScreen();

MyScreen myScreen = new MyScreen();

Environment::getEnvironment().addCustomEventListener(myScreen);

tabScreen.add(myScreen);

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:
Hi, you'd just need this

Hi, you'd just need this bit:

{syntaxhighlighter brush: cpp;fontsize: 100; first-line: 1; }void MyScreen::customEvent(const MAEvent& event)
{
//Check to see if this is a location event
if(event.type == EVENT_TYPE_LOCATION)
{
MALocation& loc = *(MALocation*)event.data;
/* Do what you want with the location */
}
}
{/syntaxhighlighter}

 

aren372
aren372's picture
Offline
Mobile Conjurer
Joined: 28 Jul 2012
Posts:
rival wrote: Hi, you'd just

rival wrote:

Hi, you'd just need this bit:

{syntaxhighlighter brush: cpp;fontsize: 100; first-line: 1; }void MyScreen::customEvent(const MAEvent& event)
{
//Check to see if this is a location event
if(event.type == EVENT_TYPE_LOCATION)
{
MALocation& loc = *(MALocation*)event.data;
/* Do what you want with the location */
}
}
{/syntaxhighlighter}

 

hi sam, thanks for your quick reply, I've tried your code, but it only work in Moblet class,

In my screen class, it never receive a custom event, But what I want is receiving location event in my screen class

Login or register to post comments