Follow

Reverse geocoding example

Introduction

This sample demonstrates how to obtain current GPS position and converts it into an address. Functions used are GetActualGpsPosition and GetLocationInfo.

C#

        GetAddress();

        void GetAddress()
        {
            int lat;
            int lon;
            GetActualGpsPosition(true, out lat, out lon);
            string address = ReverseGeoCode(lat, lon);
            Debug.WriteLine("address:" + address);
        }

        public void GetActualGpsPosition(bool bSatellitesInfo, out int lat, out int lon)
        {
            SError err;
            SGpsPosition gpos = new SGpsPosition();
            int ret = CApplicationAPI.GetActualGpsPosition(out err, out gpos, bSatellitesInfo, 0);
            lat = gpos.Latitude;
            lon = gpos.Longitude;
        }

        string ReverseGeoCode(int lat, int lon)
        {
            string strAddress;
            SError err;
            LONGPOSITION lp = new LONGPOSITION(lon, lat);
            SRoadInfo sri = new SRoadInfo();
            int ret = CApplicationAPI.GetLocationInfo(out err, lp, out strAddress, out sri, 0);
            if (ret != 1)
            {
                return "";
            }
            return strAddress;
        }
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments