Profile | Register | Active Topics | Search | FAQ

Advanced Search
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 GpsGate
 GpsGate for Developers
 GUIDE: Show street address in real time.
 New Topic  Reply to Topic
 Printer Friendly
Digg this
Author Previous Topic Topic Next Topic  

johan
Forum Admin

Sweden
15338 Posts

Posted - 02/17/2010 :  12:21:38  Show Profile  Visit johan's Homepage  Reply with Quote
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/samples/RealTimeAddress.zip

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
Senior Member

283 Posts

Posted - 02/18/2010 :  15:37:17  Show Profile  Visit mti's Homepage  Reply with Quote
Well... sorry to add garbage to this topic but I have to say this: nice, really nice shot!

Thanks

Edited by - mti on 02/18/2010 15:37:37
Go to Top of Page

GRACO
Advanced Member

657 Posts

Posted - 02/18/2010 :  15:56:26  Show Profile  Reply with Quote
For the non-developer, any plans to make this as a plugin?

regards!
Go to Top of Page

johan
Forum Admin

Sweden
15338 Posts

Posted - 11/07/2011 :  09:24:47  Show Profile  Visit johan's Homepage  Reply with Quote
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/customizing_the_vehicle_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
Go to Top of Page

emalanre
New Member

Nigeria
4 Posts

Posted - 11/15/2011 :  08:50:30  Show Profile  Visit emalanre's Homepage  Reply with Quote
Am a new user to gpsgate and it's a good idea to have the realtime address as a plugin.

Regards
Go to Top of Page

Alon
Senior Member

101 Posts

Posted - 12/29/2011 :  22:27:41  Show Profile  Reply with Quote
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":


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.
Go to Top of Page

pmckinney
New Member

Australia
3 Posts

Posted - 05/07/2012 :  02:31:15  Show Profile  Visit pmckinney's Homepage  Reply with Quote
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
Go to Top of Page

johan
Forum Admin

Sweden
15338 Posts

Posted - 05/07/2012 :  03:29:14  Show Profile  Visit johan's Homepage  Reply with Quote
pmckinney: Yes, we will consider this for coming updates. I can really see your point.

Regards,
Johan

GpsGate Support
Go to Top of Page

rosol
Average Member

83 Posts

Posted - 05/15/2012 :  08:39:14  Show Profile  Reply with Quote
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
Go to Top of Page

johan
Forum Admin

Sweden
15338 Posts

Posted - 05/15/2012 :  08:53:57  Show Profile  Visit johan's Homepage  Reply with Quote
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
Go to Top of Page

rosol
Average Member

83 Posts

Posted - 05/15/2012 :  09:19:51  Show Profile  Reply with Quote
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.
Go to Top of Page

rosol
Average Member

83 Posts

Posted - 05/15/2012 :  09:28:46  Show Profile  Reply with Quote
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>
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
GpsGate Forum © 2014 GpsGate AB Go To Top Of Page