Quick C# help needed. set, get, override

Associate
Joined
29 Dec 2007
Posts
1,414
Location
London
Hey guys. im currently making a game for a windows mobile

The problem im having is probably very very simple just I just cant seem to work it out

Its a treasurehunt game, i need to be able to read gps info from the device. The two files im having problems with are:

form3.cs
gpsMonitor.cs

from form3.cs i need to get the latitude and longitude values from gpsMonitor.cs

gpsMonitor.cs is split into two classes: gpsMonitor() and gpsCoordinate(lat, lng)

the class gpsMonitor opens a serial port, validates sentences, along with aload of other stuff (unimportant atm). when it has a valid sentence it will extract the lat and long decimal values and call gpsCoordinate() with the two values as parameters

gpsCoordinate class looks like this:


public class GpsCoordinate
{
private decimal latitude;
private decimal longitude;
private const string strFormat = "Latitude: {0} degrees /t Longitude: {1} degrees";

public GpsCoordinate(decimal lat, decimal lng)
{
Latitude = lat;
Longitude = lng;
}

public decimal Latitude
{
get { return latitude; }
set { latitude = value; }
}

public decimal Longitude
{
get { return longitude; }
set { longitude = value; }
}

public override string ToString ()
{
return String.Format(strFormat, latitude, longitude);
}
}



what i do from form3.cs is make a new instance of gpsMonitor (threaded by the way) then what i need to do is collect lat and long from the gpsCoordinate class. But since its in this set,get,override stuff i have no idea what to do :(

i can get info from the gpsMonitor class but since it is receiving invalid sentences 95% of the time its abit useless :(

Anyone albe to shed some light? thanks :)
 
The thing is i cant create an instance of GpsCoordinate because I dont have the lat/lng decimals.

I create an instance of gpsMonitor()

GpsMonitor() then reads from the serial port, validates sentences and then extracts the lat/lng decimals. It then calls GpsCoordinate like so:

location = new GpsCoordinate( lat / 100 , lng / 100);

So its put lat/lng decimals into GpsCoordinate, which then runs the code in the first post.

n.b. I cant grab the data straight from GpsMonitor because its set to private.

So in form3 ive created a new instance of GpsMonitor()

GpsMonitor myGpsMonitor = new GpsMonitor();

What i need to work out is how to then get the data from GpsCoodinate, without actually calling it directly myself.

Hopefully that makes more sense? im pretty rubbish at programming to be honest :(

so thanks guys :)
 
Back
Top Bottom