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!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hi, you'd just need this bit:

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 */
  }
}

 

aren372
aren372's picture
Offline
Mobile Conjurer
Joined: 28 Jul 2012
Posts:

rival wrote:

Hi, you'd just need this bit:

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 */
  }
}

 

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

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

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

void customEvent(const MAEvent& event);

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

void show();

and in the cpp add

void MyScreen::show()
{
  Environment::getEnvironment().addCustomEventListener(this);
   Screen::show();
}

 

 

aren372
aren372's picture
Offline
Mobile Conjurer
Joined: 28 Jul 2012
Posts:

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);