Click here to Skip to main content
15,867,141 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Dear guys,

I am currently working on a GPS tracking software. It should implement a function to trigger GPS data logging if GPS enter in a specific area and stop logging after going out of boundary.

Anyway, My problem is if I select GPS as a observable object and make a GPSMonitor class to monitor its status. I registered two events based on my gpsmonitor, I found that if GPS enter in the bounding area, the logging function works, but the other event never been triggered. I think there are some problems for my programming skills.

I registered my GPS monitor like this way:
C#
GPSMonitor gpsmonitor = new GPSmonitor (_tempX, _tempY, corners, _Time, sct, polygonGeofence);


and I then attached two events to it, one happened when gps enter a specific area, while the other one happened if gps go out of geofence.
C#
gpsmonitor.GeofencePositioned += new GPSMonitor.PositionInGeofenceEventHandler(RaiseInEvent);

C#
gpsmonitor.GeofenceOutPositioned += new GPSMonitor.PositionInGeofenceEventHandler(RaiseOutEvent);

and gpsmonitor start by
C#
gpsmonitor.GeofenceSDetermination();


The methods happened by two events are the following two sections.

this following part works well when GPS enter in the area:
C#
 private void RaiseAlarmEvent(object sender, PositionInGeofenceEventArgs e)
{
   DemoServer.SendText("1", DemoServer.IndexOf(Socket));
   BtnRecordData.BeginInvoke(new System.EventHandler(BtnRecordData_Click));
}


but second event below part doesn't work. it should trigger the Stop Button stopping, but it nothing happened.
C#
private void RaiseAlarmEvent(object sender, PositionInGeofenceEventArgs e)
{
   gpsmonitor.GeofenceOutPositioned -= new GPSMonitor.PositionInGeofenceEventHandler(RaiseInEvent)
   DemoServer.SendText("2", DemoServer.IndexOf(Socket));
   BtnRecordData.BeginInvoke(new System.EventHandler(BtnRecordStop_Click));
}


I think there is less possible problems on my condition to determine the entry or out of GPS because I have tested it. I donnot know if there is problems on event registration.

Many thanks if any of you could give me suggestions and guidance.
Posted
Updated 2-Nov-11 10:31am
v3

1 solution

Is this a typo?

C#
gpsmonitor.GeofenceOutPositioned += new GPSMonitor.PositionInGeofenceEventHandler(RaiseInEvent);

gpsmonitor.GeofenceOutPositioned += new GPSMonitor.PositionInGeofenceEventHandler(RaiseOutEvent);


If not, there's your bug.
 
Share this answer
 
v3
Comments
HAOYE850815 2-Nov-11 16:35pm    
I am so sorry, It is a typo mistake. I have changed it.

Could you please help me to have a look the event registration? I am not sure why only one event triggered. It bothered me for several days. Many thanks.
Nish Nishant 2-Nov-11 16:37pm    
If the event is not firing when it should, it may be because you are using the component incorrectly or perhaps even a bug in the library. Either way you should probably ask the guys who wrote/sold this component. They'd know best how to resolve this.
HAOYE850815 2-Nov-11 16:47pm    
Actually I programmed the event for myself. The entry condition is all right when I have tested. Could you please tell if you can find any problems on the events, particularly the register. Is there any problem if I write two events using one same delegate.many thanks for your reply
Nish Nishant 3-Nov-11 7:48am    
You'll need to step through the code that fires the events and see what's causing it to not fire.
Espen Harlinn 2-Nov-11 17:09pm    
Congratulations - this was your answer number 1000 :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900