Click here to Skip to main content
15,886,799 members
Articles / Mobile Apps

Using the Skyhook Wireless XPS Positioning Service in Managed Code

Rate me:
Please Sign up or sign in to vote.
4.95/5 (15 votes)
20 Jan 2009CPOL28 min read 88.9K   1.4K   57  
Wrapper and sample programs demonstrating the use of the Skyhook Wireless XPS SDK (hybrid position system using GPS, WiFi Positioning, and Celltower positioning)
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using J2i.Net.FindMe.Interface;
using J2i.Net.FindMe.Common;

namespace J2i.Net.FindMe.Controls
{
    public partial class MainForm : Form
    {

        delegate void SetTextDelegate(Control c, string text);

        SetTextDelegate _setText;
       public  ISession UserSession
        {
            get;
            set;
        }

        public MainForm(ISession userSession)
        {
            _setText = new SetTextDelegate(this.SetText);
            UserSession = userSession;
            InitializeComponent();
        }

        void DisplayGeneralSettings()
        {
            SettingsForm settingsForm = new SettingsForm(UserSession.UserSettings);
            if (settingsForm.ShowDialog() == DialogResult.OK)
            {
                UserSession.UserSettings.Save();
            }
        }



        void SetText(Control c, string text)
        {
            if (c.InvokeRequired)
            {
                c.Invoke(_setText, new object[] { c, text });
            }
            else
            {
                c.Text = text;
            }
        }
        
        void DisplayContactSettings()
        {
            ContactApprovalForm caf = new ContactApprovalForm(UserSession.UserContactApproval);
            if (caf.ShowDialog() == DialogResult.OK)
            {
                UserSession.UserContactApproval.Save();
            }
        }

        private void miGeneralSettings_Click(object sender, EventArgs e)
        {
            DisplayGeneralSettings();
        }

        private void miContactSettings_Click(object sender, EventArgs e)
        {
            DisplayContactSettings();
        }

        private void miPositioningTest_Click(object sender, EventArgs e)
        {
            (new PositioningServices(UserSession)).ShowDialog();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            //Bitmap bm = new Bitmap(Path.Combine(ApplicationEnvironment.ApplicationFolder, "Assets\\Images\\SampleMap.jpg"));
            //mapDisplay.MapImage = bm;
            
 
        }

        void MapRetrieved(object sender, MapRetrievedEventArgs args)
        {
            if (args.Success)
            {
                mapDisplay.MapImage = args.Map;
                SetText(statusBar, "Location Displayed");
            }
            else
            {
                SetText(statusBar, "Map could not be retrieved");
            }
        }

        private void miMyLocation_Click(object sender, EventArgs e)
        {
            int defaultZoom = (UserSession.GeoManager.MaxZoomLevel*2+UserSession.GeoManager.MinZoomLevel*1)/3;
            Size s = new Size(mapDisplay.Width * 3, mapDisplay.Height * 3);
            LocationResponse lr = new LocationResponse(UserSession.LocationProvider.LastLocation,string.Empty, "My Location", null, null);

            UserSession.GeoManager.GetMapAsync(new MapRequest(UserSession.LocationProvider.LastLocation, s, defaultZoom,new ILocationResponse[]{lr}), new MapRetrievedCallback(MapRetrieved), null);
            SetText(statusBar, "Obtaining map...");

            //Image mapImage = UserSession.GeoManager.GetMap(UserSession.LocationProvider.LastLocation, s, defaultZoom);
            //mapDisplay.MapImage = mapImage;
            //string locationDescription = UserSession.GeoManager.GetLocationDescription(UserSession.LocationProvider.LastLocation);
            //SetText(statusBar, locationDescription);
        }

        private void miExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void miKnownLocations_Click(object sender, EventArgs e)
        {
            LastLocationForm llf = new LastLocationForm(UserSession);
            if (llf.ShowDialog() == DialogResult.OK)
            {
                switch (llf.ExitCommand)
                {
                    case LastLocationForm.ExitCommands.DisplayMap:
                        {
                            int defaultZoom = (UserSession.GeoManager.MaxZoomLevel * 2 + UserSession.GeoManager.MinZoomLevel * 1) / 3;
                            Size s = new Size(mapDisplay.Width * 3, mapDisplay.Height * 3);
                            LocationResponse lr = new LocationResponse(UserSession.LocationProvider.LastLocation,string.Empty, "My Location", null, null);

                            UserSession.GeoManager.GetMapAsync(new MapRequest(llf.Location.LastKnownLocation, s, defaultZoom, new ILocationResponse[] { llf.Location, lr }), new MapRetrievedCallback(MapRetrieved), null);
                            SetText(statusBar, "Obtaining map...");
                        }
                        break;
                    case LastLocationForm.ExitCommands.Nop:
                        {

                        }
                        break;
                    default:
                        break;
                }
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
I attended Southern Polytechnic State University and earned a Bachelors of Science in Computer Science and later returned to earn a Masters of Science in Software Engineering. I've largely developed solutions that are based on a mix of Microsoft technologies with open source technologies mixed in. I've got an interest in astronomy and you'll see that interest overflow into some of my code project articles from time to time.



Twitter:@j2inet

Instagram: j2inet


Comments and Discussions