User avatar
johan
GpsGate
Posts: 14072
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

GUIDE: Show street address in real time.

Wed Feb 17, 2010 9:21 pm

Requires GpsGate Server 2.2 build 1799 or later

This article is for developers only!

This plugin enables real time street address in vehicle list.

Here is a sample on how to write a "Service PlugIn" to Franson NMEA Service. This is a way to integrate in real time into the core of the GpsGate Server functionality. When started it assigns callbacks for when new devices connects and authenticates, and when position reports from the trackers are received. The street address for the positions are looked up using the geocoder and the address is assigned to the vehicles/user's "description" field. The description field can in turn be displayed in the vehcile list in Map View in VehicleTracker.

This is just one of many types of plugins that can be added to GpsGate Server, the complete architecture is built up from plugins, which you can add and customize!

You can download the project here:
http://franson.com/gpsgateserver/sample ... ddress.zip

Code: Select all

using System;
using System.Collections.Generic;
using System.Text;

using Franson.Reflection;
using Franson.DAO;
using Franson.Directory;
using Franson.Threading;
using Franson.Geo.Geocoding;
using Franson.Geo;

using GpsGate.Online.Directory.Service;
using GpsGate.Online.Message;
using GpsGate.Online.Net;
using GpsGate.Online;

namespace RealTimeAddress
{
    /// <summary>
    /// Enables real time address in user's description field.
    /// </summary>
    [Loadable(Installable = true, Description = "Real time address")]
    public class AddressService : ServicePlugin
    {
        #region Start / Stop

        /// <summary>
        /// Called when this service plugin is started.
        /// </summary>
        protected override void OnStart()
        {
            NmeaServiceApplication nmeaApp = NmeaServiceApplication.GetNmeaServiceApplicationSingleton();

            // Event for when new authenticated connection is made.
            // That is a tracker that connects and logins correctly.
            nmeaApp.NewAuthenticatedConnection += new GateApplication.NewAuthenticatedConnectionHandler(
nmeaApp_NewAuthenticatedConnection);
        }

        /// <summary>
        /// Called when this service plugin is stopped.
        /// </summary>
        protected override void OnStop()
        {
        }

        #endregion

        #region Event handling

        /// <summary>
        /// Called when a connection is authenticated.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="nmeaListener"></param>
        /// <param name="nmeaConn"></param>
        private void nmeaApp_NewAuthenticatedConnection(GateApplication service,
NmeaListener nmeaListener, NmeaConnection nmeaConn)
        {
            // This method is stateless, therefor it is thread safe.
            // If you introduce class variables, remember to make usage thread safe.

            // Applications this tracker's owner is member of.
            int[] arrAppIDs = nmeaConn.AppIDs;

            if (arrAppIDs.Length >= 1)
            {
                // Create a geocoder for this connection.
                GeocoderFactory gcFactory = new GeocoderFactory();
                Geocoder geocoder = gcFactory.GetGeocoderByApplicationId(arrAppIDs[0]);

                // Save geocoder as a session object on this connection.
                nmeaConn.SetCustomObject("RealTimeAddress", geocoder);

                // Add an event sink to listen to each new position report coming in from tracker
                nmeaConn.GateMessageProcessed += new NmeaConnection.GateMessageProcessedHandler(
nmeaConn_GateMessageProcessed);

                // Now we have one geocoder per connection. And a callback that will be called each time
                // a new position report (GateMessage) is sent from the tracker.
            }
        }

        /// <summary>
        /// Called for each GateMessage processed.
        /// </summary>
        /// <param name="nmeaConn"></param>
        /// <param name="gMsg"></param>
        void nmeaConn_GateMessageProcessed(NmeaConnection nmeaConn, GateMessage gMsg)
        {
            // This method is stateless, therefor it is thread safe.
            // If you introduce class variables, remember to make usage thread safe.

            // An instance of a NmeaConnection only process one GateMessage at a time.
            // You will not have two calls in parallel to this method for the same NmeaConnection.
            // However calls for different NmeaConnections are processed in parallel

            if (TrackPoint.IsNullOrEmpty(gMsg.TrackPoint) == false && gMsg.TrackPoint.Valid == true)
            {
                // This is a valid position

                // Get the geocoder for this connection
                Geocoder geocoder = nmeaConn.GetCustomObject("RealTimeAddress") as Geocoder;

                // Look up location for this position.
                List<Position> listPos = new List<Position>();
                listPos.Add(gMsg.TrackPoint.Position);

                // Get address string
                ReverseGeocodeResult result = geocoder.ReverseGeocode(listPos);
                string strAddress = result.Locations.Count >= 1 ? result.Locations[0].Address : "";

                // Since this is a long string, we only use the first most significant field.
//e.g. streat, town, country
                int iCommaIndex = strAddress.IndexOf(',');
                if (iCommaIndex != -1)
                {
                    strAddress = strAddress.Substring(0, iCommaIndex);
                }

                // Now save address in GateUser's Description field.
                // The description field can be displayed in the vehicle list and status tab.
                nmeaConn.GateUser.Description = strAddress;
                nmeaConn.GateUser.Update();
            }
        }

        #endregion

        #region Install

        /// <summary>
        /// Called when service is installed. Enable by default.
        /// </summary>
        /// <param name="typeInfo"></param>
        public override void Install(LoadableType typeInfo)
        {
            Enabled = true;

            base.Install(typeInfo);
        }

        #endregion

    }
}


Make references to the following DLLs (you find them in the ZIP file in the "Franson NMEA Service" folder"
Franson.dll
GpsGate.Online.dll
Jayrock.Jason.dll
NLog.dll

Make sure your project reference the same version of the DLLs as the GpsGate Server installation uses

Install
1. Copy the plugin DLL to "Franson NMEA Service" folder.
2. Restart NMEA Service.

A complete reference manual for .NET can be downloaded here:
http://franson.com/gpsgateserver/guide.asp

Here are some guide lines on how to debug your plugin during development:
http://forum.gpsgate.com/topic.asp?TOPIC_ID=8105

Overview of GpsGate Server development here:
http://forum.gpsgate.com/topic.asp?TOPIC_ID=8097

Regards,
Johan

Franson Support

mti
Posts: 270
Joined: Thu Aug 14, 2008 5:02 pm
Contact: Website

RE: GUIDE: Show street address in real time.

Fri Feb 19, 2010 12:37 am

Well... sorry to add garbage to this topic but I have to say this: nice, really nice shot!

Thanks

GRACO
Posts: 490
Joined: Mon Sep 01, 2008 8:19 am

RE: GUIDE: Show street address in real time.

Fri Feb 19, 2010 12:56 am

For the non-developer, any plans to make this as a plugin?

regards!

User avatar
johan
GpsGate
Posts: 14072
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: GUIDE: Show street address in real time.

Mon Nov 07, 2011 6:24 pm

Here is a better way of doing this, requires only to setup a simple Event Rule

Please take a look at this blog:
http://gpsgate.com/blogComment/customiz ... hicle_list

Instead of inserting the event duration as in the blog, you can insert the Address. And to make the Event Rule always true you can for example compare Speed to greater or equal to 0.

Here you find more informative blogs:
http://gpsgate.com/blog

Here you find more VehicleTracker tips and Trix:
http://forum.gpsgate.com/topic.asp?TOPIC_ID=11259

Regards,
Johan

GpsGate Support

emalanre
Posts: 4
Joined: Mon Sep 19, 2011 11:15 am
Location: Nigeria
Contact: Website

RE: GUIDE: Show street address in real time.

Tue Nov 15, 2011 5:50 pm

Am a new user to gpsgate and it's a good idea to have the realtime address as a plugin.

Regards

Alon
Posts: 180
Joined: Wed Sep 01, 2004 3:48 pm

RE: GUIDE: Show street address in real time.

Fri Dec 30, 2011 7:27 am

Tip: How to 'automatic' deploy the plugin


If you are working with Visual Studio, go to project settings -> Compile -> Build Events and paste the following in the 'post build event command line":

Code: Select all

net stop "Franson NMEA Service"
Copy "$(TargetPath)" "C:\GpsGateServer\Franson NMEA Service"
net start "Franson NMEA Service"


This small snippet, after compilation, will stop the NMEA service, copy the compiled dll plug in and restart the NMEA service.

Enjoy.

pmckinney
Posts: 3
Joined: Thu Mar 29, 2012 10:25 am
Location: Australia
Contact: Website

RE: GUIDE: Show street address in real time.

Mon May 07, 2012 11:31 am

Interesting article on reverse geocoding. So far I have taken Johan's advice to use the Event Rule to display an address in the Vehicle List.

That is fine, but ideally we would like to see the Address for each of the points in the Track points (selected tracks), and also for the Alarm panel (instead of Lat/Long). Can the plugin that you outline in this article be used for both of those? If so, how could it be used to add columns to the Alarm and Track Points panels?

Regards,
Paul McKinney

User avatar
johan
GpsGate
Posts: 14072
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: GUIDE: Show street address in real time.

Mon May 07, 2012 12:29 pm

pmckinney: Yes, we will consider this for coming updates. I can really see your point.

Regards,
Johan

GpsGate Support

rosol
Posts: 95
Joined: Mon Feb 13, 2012 3:11 pm

RE: GUIDE: Show street address in real time.

Tue May 15, 2012 5:39 pm

I have problem with reverse geocode.
I have 20 trucks on my own server and johan's solution doesn't work correctly.
On many trucks address doesn't appeard. Whats going on? Am I exceeded googles requests per day?
Is it possible to use my own reverse geocode proxy/server?
Regards
Michal

User avatar
johan
GpsGate
Posts: 14072
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: GUIDE: Show street address in real time.

Tue May 15, 2012 5:53 pm

Most likely you exceed the Google quota. Install the LogFiles plugin, and you can see errors under C:\GpsGateServer\ErrorLogs

Here are more info on Google Maps, you can purchase a license for us to get a larger geocoding quota
http://gpsgate.com/purchase/google_maps

Here are other map/geocoding options:
http://forum.gpsgate.com/topic.asp?TOPIC_ID=10087

Regards,
Johan

GpsGate Support

rosol
Posts: 95
Joined: Mon Feb 13, 2012 3:11 pm

RE: GUIDE: Show street address in real time.

Tue May 15, 2012 6:19 pm

When I change a geocoder to cloudmade or HTTPgeocoder, it doesn't work;/
I've tested on Request Address and despite of that I want to use other geocoder, it use Google geocoder.

rosol
Posts: 95
Joined: Mon Feb 13, 2012 3:11 pm

RE: GUIDE: Show street address in real time.

Tue May 15, 2012 6:28 pm

In addition, I paste example XML result on my reverse geocode and it returns 0 location found.

XML example:
<location>
<Address>Address</Address>
<AdministrativeAreaName>AdministrativeAreaName</AdministrativeAreaName>
<CityName>CityName</CityName>
<CountryName>CountryName</CountryName>
<PostalCodeNumber>PostalCodeNumber</PostalCodeNumber>
<StreetBox>StreetBox</StreetBox>
<StreetName>StreetName</StreetName>
<StreetNumber>StreetNumber</StreetNumber>
<SubAdministrativeAreaName>SubAdministrativeAreaName</SubAdministrativeAreaName>
</location>

Return to “GpsGate for Developers”