Franson GPS Tools & C#

  • Thread starter Thread starter BigAl.NZ
  • Start date Start date
B

BigAl.NZ

Hi Guys,

I am trying to get a fix from a GPS using a SDK called Franson GPS
tools. http://www.franson.com/gpstools

I have gotten quite far on my own but am stuck - when I create a
instance of class called GpsFix i get a compile error that no
constructors are defined.

It appears to me that I must set the position property of gpsfix before
I use it? But I also see that position is a class in itself?

My code is below. If someone can see where I am going wrong please
advise.

Thanks heaps.

-Al


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

GpsToolsNET.License objLicense = new GpsToolsNET.License();
objLicense.LicenseKey = "o8h1j88qlSqkaJHiu27oixldj7redk4YoCh3";

// Create parser
GpsToolsNET.NmeaParser objparser = new GpsToolsNET.NmeaParser();
GpsToolsNET.GpsFix objFix = new GpsToolsNET.GpsFix();

objparser.NoEvents = true;
objparser.PortEnabled = true;

objparser.GetGpsFix(3000, 2);
}

private void btnConvert_Click(object sender, EventArgs e)
{
MessageBox.Show(textBoxLatitude.Text + " " + textBoxLongitude.Text);
}
}
}
 
I see now that I get access to the GpsFix object with a line like:

GpsToolsNET.GpsFix objFix = objparser.GetGpsFix(3000, 2);

What I dont understand is why the syntax is different, I mean so far I
have seen that instances of classes are created with:

GpsToolsNET.GpsFix objFix = new GpsToolsNET.GpsFix();

So why does creating this object (instance) differ from the syntax
above?

Cheers

-Al
 
I see now that I get access to the GpsFix object with a line like:

GpsToolsNET.GpsFix objFix = objparser.GetGpsFix(3000, 2);

What I dont understand is why the syntax is different, I mean so far I
have seen that instances of classes are created with:

GpsToolsNET.GpsFix objFix = new GpsToolsNET.GpsFix();

So why does creating this object (instance) differ from the syntax
above?

Constructors are special methods that are defined and invoked with a
particular syntax. But there's nothing to stop other methods of the
class returning an instance of the class. For example, String.Replace
returns a new String.

And some classes might hide their constructors and require clients to
call a factory method if they want an instance. The same effect can
sometimes be achieved by having no parameterless constructor, and
therefore requiring clients to provide parameters, but having an
explicit factory method makes it more obvious what's happening.

For example, the Graphics class in WinForms cannot be directly created,
because there's not really any such thing as a standalone Graphics - if
you want one, you have to provide an Image, or a window, or a DC, for
the Graphics to be tied to. So the Graphics class has:

public static Graphics FromImage(Image image)
public static Graphics FromHwnd(IntPtr hwnd)
public static Graphics FromHdc(IntPtr hdc)

Note that in this case we couldn't readily use parameterised
constructors instead, because both the latter two take an IntPtr and
there would be no way to tell what it was if we just had

public Graphics(IntPtr handle) // handle to what?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top