Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
The below code is for livetracking of vehicle than how to show tooltip?

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
//using System.Windows.Controls;
using Microsoft.Phone.Controls;
using System.Device.Location;
using Microsoft.Phone.Controls.Maps;
using WindowsPhoneApplication1.GPSService;
using WindowsPhoneApplication1.Class;
using System.Xml;
using System.Xml.Linq;

//using WindowsPhoneApplication1.TerraService;

using System.Xml.Schema;
using System.Text;
using System.IO;

namespace WindowsPhoneApplication1
{
    
    public partial class MainPage : PhoneApplicationPage
    {
        GPSService.ServiceSoapClient svc = new ServiceSoapClient();
       // GetDashboardLocationData.ServiceSoapClient client = new GetDashboardLocationData.ServiceSoapClient();
    
        GeoCoordinateWatcher myCoordinateWatcher;
        double latitude, longitude;
        public Pushpin pin;

        Location l = new Location();
        IList<location> l1;
       
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            pin = null;
            
            //client.ConvertLonLatPtToNearestPlaceCompleted += new EventHandler<terraservice.convertlonlatpttonearestplacecompletedeventargs>(client_ConvertLonLatPtToNearestPlaceCompleted);
            //map1.ZoomBarVisibility = System.Windows.Visibility.Visible;
            l1 = new List<location>();
            pp1=new List<pushpin>();

           // client.DownloadStringCompleted+=new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
            SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;

            pin = new Pushpin();

            System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
            dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 10);
            dispatcherTimer.Start();

        }
        IList<pushpin> pp1;

        private void dispatcherTimer_Tick(object sender, EventArgs e)
         {
            svc.getDashboardLocationDataAsync(51);
           // svc.getLocationDataAsync(51);
            if (cmbVehicle.Items.Count() == 0)
            {
                //cmbVehicle.Items.Add(l1);
                for (int i = 0; i < l1.Count(); i++)
                {
                    cmbVehicle.Items.Add(l1[i].vehicleid);
                }
                
            }
     //    svc.getLocationDataForDetailsAsync("51");
          map1.Children.Remove(pin);
          pin.Location = new System.Device.Location.GeoCoordinate(l.latitude,l.longitude);
          ToolTipService.SetToolTip(pin, l.vehicleid);
          pin.Content = new Rectangle()
             {
                 Fill = image,
                 StrokeThickness = 5,
                 Height = 40,
                 Width = 30,

             };
          
        //  ToolTipService.SetToolTip(pin, l.vehicleid);
          
          map1.Children.Add(pin);
          map1.Center = new GeoCoordinate(l.latitude, l.longitude);
            
        }
        //{
        //    svc.getDashboardLocationDataAsync(51);
        //    for (int i = 0; i < pp1.Count; i++)
        //    {
        //        map1.Children.Remove(pp1[i]);
        //    }
        //    for (int i = 0; i < l1.Count; i++)
        //    {
        //        Pushpin pin1 = new Pushpin();
        //        pin1.Location = new System.Device.Location.GeoCoordinate(l1[i].latitude, l1[i].longitude);


        //        pin1.Content = new Rectangle()
        //        {
        //            Fill = image,
        //            StrokeThickness = 5,
        //            Height = 40,
        //            Width = 30,

        //        };
        //        pp1.Add(pin1);
        //        map1.Center = new GeoCoordinate(l1[i].latitude, l1[i].longitude);
        //    }
        //    for (int i = 0; i < pp1.Count(); i++)
        //    {
        //        map1.Children.Add(pp1[i]);
                  
            
        //    }
           
        
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            //l.latitude = 22.187405;
            //l.longitude = 72.861328;
            //map1.Center = new GeoCoordinate(l.latitude, l.longitude);
            map1.ZoomLevel = 5;
            map1.ZoomBarVisibility = Visibility.Visible;
            myCoordinateWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
            myCoordinateWatcher.PositionChanged += new
              EventHandler<geopositionchangedeventargs><geocoordinate>>(myCoordinateWatcher_PositionChanged);

               // svc.getLocationDataForDetailsAsync("vehicleid");
               svc.getLocationDataForDetailsCompleted += new EventHandler
            <gpsservice.getlocationdatafordetailscompletedeventargs>(svc_getDataCompleted);
            svc.getDashboardLocationDataAsync(51);
            svc.getDashboardLocationDataCompleted += new EventHandler<getdashboardlocationdatacompletedeventargs>(svc_getDashboardLocationDataCompleted);
            //svc.getLocationDataForDetailsCompleted += new EventHandler<gpsservice.getlocationdatafordetailscompletedeventargs>(svc_getDataCompleted);
        }
        //private void svc_getDataCompleted(object sender, GPSService.getLocationDataForDetailsCompletedEventArgs e)
        //{
        //    string xml = e.Result;


        //    var test = XElement.Parse(xml)
        //        .Descendants("map")
        //        .First().Descendants("longitude").First()
        //        .Value;
        //    l.longitude = Convert.ToDouble(test);

        //    test = XElement.Parse(xml)
        //     .Descendants("map")
        //     .First().Descendants("latitude").First()
        //     .Value;
        //    l.latitude = Convert.ToDouble(test);


        //}
        private void svc_getDashboardLocationDataCompleted(object sender, GPSService.getDashboardLocationDataCompletedEventArgs e)
        {
            string xml = e.Result;

            l1.Clear();

            var maps = XElement.Parse(xml)
            .Descendants("map");
            foreach (XElement x in maps)
            {
                Location ln = new Location();

                var test = x.Descendants("longitude").First()
            .Value;
                ln.longitude = Convert.ToDouble(test);

                test = x.Descendants("latitude").First()
                  .Value;
                ln.latitude = Convert.ToDouble(test);

                test = x.Descendants("vehicle_no").First().Value;

                ln.vehicleid = test;

                //cmbVehicle.Items.Add(ln.vehicleid);
                
                l1.Add(ln);
               // cmbVehicle.Items.Add(l1);                
            }
        }

            //var list = from ele in XDocument.Parse(@"C:\Users\chitrang\Documents\Visual Studio 2010\Projects\WindowsPhoneApplication1\WindowsPhoneApplication1\xml file\vehicle.xml").Descendants("map")
            //           select new
            //           {
            //               Vehicle = (string)ele.Element("vehicle_no")
            //           };
            //foreach (var t in list)
            //{
            //    ComboBox1.Items.Add(t);
            //}
          
        //private void svc_getDataCompleted(object sender, GPSService.getLocationDataForDetailsCompletedEventArgs e)
        //{
        //    string xml = e.Result;


        //    var test = XElement.Parse(xml)
        //        .Descendants("map")
        //        .First().Descendants("longitude").First()
        //        .Value;
        //    l.longitude = Convert.ToDouble(test);

        //    test = XElement.Parse(xml)
        //     .Descendants("map")
        //     .First().Descendants("latitude").First()
        //     .Value;
        //    l.latitude = Convert.ToDouble(test);

        //    test = XElement.Parse(xml)
        //     .Descendants("map")
        //     .First().Descendants("vehicle_no").First()
        //     .Value;

        //    l.vehicleid = test;

        //}
       void myCoordinateWatcher_PositionChanged(object sender, GeoPositionChangedEventArgs<geocoordinate> e)
        {
            if (!e.Position.Location.IsUnknown)
            {
                l.latitude = e.Position.Location.Latitude;
                l.longitude = e.Position.Location.Longitude;
                map1.Center = new GeoCoordinate(l.latitude, l.longitude);
                map1.SetView(new GeoCoordinate(l.latitude, l.longitude), map1.ZoomLevel);
                myCoordinateWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
                 myCoordinateWatcher.PositionChanged += new EventHandler<geopositionchangedeventargs><geocoordinate>>(myCoordinateWatcher_PositionChanged);
              //  svc.getDashboardLocationDataAsync(51);//"GJ12Y8277(T-07)");et

                //svc.getDashboardLocationDataCompleted += new EventHandler<getdashboardlocationdatacompletedeventargs>(svc_getDataCompleted1);
                map1.Center = new GeoCoordinate(l.latitude, l.longitude);
                map1.Children.Add(pin);
            }
        }
                
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            map1.Children.Remove(pin);
            pin = null;
        }

    ImageBrush image = new ImageBrush()
        {
                    ImageSource = new System.Windows.Media.Imaging.BitmapImage
                    (new Uri("http://www.iconshock.com/img_jpg/SOPHISTIQUE/communications/jpg/128/car_icon.jpg"))
                    
        };

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        map1.Mode = new RoadMode();

    }

    public int i { get; set; }

    private void cmbVehicle_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {

        if (cmbVehicle.Items.Count > 0)
        {
           // svc.getLocationDataForDetailsCompleted += new EventHandler<getlocationdatafordetailscompletedeventargs>(svc_getLocationDataForDetailsCompleted);

            svc.getLocationDataForDetailsAsync(cmbVehicle.SelectedItem.ToString());
        }
    }
    private void svc_getDataCompleted(object sender, GPSService.getLocationDataForDetailsCompletedEventArgs e)
    {
        string xml = e.Result;

        var test = XElement.Parse(xml)
            .Descendants("map")
            .First().Descendants("longitude").First()
            .Value;
        l.longitude = Convert.ToDouble(test);

        test = XElement.Parse(xml)
         .Descendants("map")
         .First().Descendants("latitude").First()
         .Value;
        l.latitude = Convert.ToDouble(test);

        test = XElement.Parse(xml)
         .Descendants("map")
         .First().Descendants("vehicle_no").First()
         .Value;

        l.vehicleid = test;
    }
  }
}
Posted
Updated 7-Aug-13 5:14am
v2
Comments
TrushnaK 7-Aug-13 1:24am    
Where is the question..
Thanks7872 7-Aug-13 2:12am    
Just an abuse.
Chitrang Shah 7-Aug-13 5:24am    
in the beginning of the code where it get start on the very first line.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900