ZAMKNIJ
Wątek zamknięty

Tryb drzewa | Tryb normalny |
Ocena wątku:
  • 1 Głosów - 5 Średnio
  • 1
  • 2
  • 3
  • 4
  • 5

Route Service połączony z GeoCoordinateWatcher

 
juju
Nowy
Liczba postów: 1
Post: #1

Route Service połączony z GeoCoordinateWatcher


Witam. Mam program, który generuje trasę GPS, pobierając dlugosc i szerokosc geograficzną na podstawie adresu wpisanego w programie. Chciałabym dołączyć do tego route service, aby oprócz punktów trasy, wyświetlał również drogę. Niestety jedynym efektem jest błąd w tej linijce:
BingMapDemo.RouteService.RouteResponse _result = ((BingMapDemo.RouteService.RouteResponse)(base.EndInvoke("CalculateRoute", _args, result))); -- to jest Reference.cs
BŁAD:
The argument value must be between 2 and 25.
Parameter name: Waypoints
Actual value was 0.
Kod:
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 Microsoft.Phone.Controls;
using Microsoft.Phone.Controls.Maps;
using System.Device.Location;
using Microsoft.Phone.Controls.Maps.Platform;
using Microsoft.Phone.Reactive;
using System.Threading;
using BingMapDemo.GeoCode;
using BingMapDemo.RouteService;
using System.Linq;
using System.Collections.ObjectModel;



namespace BingMapDemo
{
    public partial class MainPage :  PhoneApplicationPage
    {
        GeoCoordinateWatcher _geoCoordinateWatcher;
        GeocodeServiceClient _svc;
        public double dlugosc;
        public double szerokosc;
        List<GeoCoordinate> locations = new List<GeoCoordinate>();
        RouteServiceClient routeService = new RouteServiceClient("BasicHttpBinding_IRouteService");
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            bingMap.CredentialsProvider = new ApplicationIdCredentialsProvider("Aqd5C5K03RH7IzzYAA9PPTqENhaSYivqu_a-_EDERCs2DjQJg8HIapihI7B0lYcd");
            bingMap.LogoVisibility = Visibility.Collapsed;
            bingMap.CopyrightVisibility = Visibility.Collapsed;
            _geoCoordinateWatcher = new GeoCoordinateWatcher();
            //_geoCoordinateWatcher.MovementThreshold = 100;
            //_geoCoordinateWatcher.StatusChanged +=new EventHandler<GeoPositionStatusChangedEventArgs>
            //  (_geoCoordinateWatcher_StatusChanged);
            _geoCoordinateWatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>
                (_geoCoordinateWatcher_PositionChanged);

            Thread simulateGpsThread = new Thread(SimulateGPS);
            simulateGpsThread.Start();
            _svc = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService1");
            _svc.GeocodeCompleted += (s, e) =>
                {
                    var geoResult = (from r in e.Result.Results
                                     orderby (int)r.Confidence ascending
                                     select r).FirstOrDefault();
                    if (geoResult != null)
                    {
                        //this.SetLocation(geoResult.Locations[0].Latitude, geoResult.Locations[0].Longitude, 10, true);
                        dlugosc = geoResult.Locations[0].Latitude;
                        szerokosc = geoResult.Locations[0].Longitude;
                    }
                };
        }
        private void SimulateGPS()
        {
            var position = GPSPositionChangedEvents().ToObservable();
            position.Subscribe(evt => _geoCoordinateWatcher_PositionChanged(null, evt));
        }
        private IEnumerable<GeoPositionChangedEventArgs<GeoCoordinate>>
            GPSPositionChangedEvents()
        {
            //Random random = new Random();
            //while (true)
            //{
            List<String> lista = new List<String>();
            lista.Add("201 east randolph, Chicago, Illinois, USA");
            lista.Add("Buckner Terrace / Everglade Park, Dallas, Teksas, Stany Zjednoczone");



            for (int i = 0; i <= 1; i++)
            {
                req(lista[i]);
                Thread.Sleep(TimeSpan.FromSeconds(30));
                //double latitude = (random.NextDouble() * 180.0) - 90.0;
                //double longtitude = (random.NextDouble() * 360.0) - 180.0;
                yield return new GeoPositionChangedEventArgs<GeoCoordinate>(
                    new GeoPosition<GeoCoordinate>(DateTimeOffset.Now,
                        new GeoCoordinate(dlugosc, szerokosc)));
            }
                
                
            //}


        }

        private void _geoCoordinateWatcher_PositionChanged(object sender,
            GeoPositionChangedEventArgs<GeoCoordinate> e)
        {
            this.Dispatcher.BeginInvoke(() => ChangePosition(e));
        }
        private void ChangePosition(GeoPositionChangedEventArgs<GeoCoordinate> e)
        {
            
            SetLocation(dlugosc, szerokosc, 10, true);
            txtStatus.Text = dlugosc.ToString();
        }

        /*private void _geoCoordinateWatcher_StatusChanged(object sender,
            GeoPositionStatusChangedEventArgs e)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() => StatusChanged(e));
        }

        private void StatusChanged(GeoPositionStatusChangedEventArgs e)
        {
            switch (e.Status)
            {
                case GeoPositionStatus.Disabled:
                    txtStatus.Text = "Usługa pozycjonowania jest wylaczona!";
                    break;
                case GeoPositionStatus.Initializing:
                    txtStatus.Text = "Włączanie usługi pozycjonowania";
                    break;
                case GeoPositionStatus.NoData:
                    txtStatus.Text = "Nie możnna ustalić bieżącej pozycji";
                    break;
                case GeoPositionStatus.Ready:
                    break;
            }
        }
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            if (!_geoCoordinateWatcher.TryStart(true, TimeSpan.FromSeconds(5)))
            {
                MessageBox.Show("Włącz usługę pozycjonowania w telefonie!", "Uwaga",
                    MessageBoxButton.OK);
            }
        }*/
        private void SetLocation(double latitude, double longtitude, double zoomLevel,
                bool showLocator)
        {
            Microsoft.Phone.Controls.Maps.Platform.Location location =
                new Microsoft.Phone.Controls.Maps.Platform.Location();
            location.Latitude = latitude;
            location.Longitude = longtitude;
            bingMap.SetView(location, zoomLevel);
            bingMapLocator.Location = location;
            if (showLocator)
            {
                locator.Visibility = Visibility.Visible;

            }
            else
            {
                locator.Visibility = Visibility.Collapsed;
            }


        }
        void req(string co)
        {
            BingMapDemo.GeoCode.GeocodeRequest request =
                new BingMapDemo.GeoCode.GeocodeRequest();
            request.Options = new GeocodeOptions()
            {
                Filters = new ObservableCollection<FilterBase>
                {
                    new ConfidenceFilter()
                    {
                        MinimumConfidence = BingMapDemo.GeoCode.Confidence.High
                    }
                }
            };
            request.Credentials = new Credentials()
            {
                ApplicationId = "AmqeYQM0AXaxA3HdM6iRiG1DJko3P_X3_8uLiaHnmFdg1mhrk7bcoznk4RMdjGHK"
            };
            request.Query = co;
            _svc.GeocodeAsync(request);

        }
    }
}
(Ten post był ostatnio modyfikowany: 22.01.2013 23:11 przez juju.)

22.01.2013 19:26

Znajdź wszystkie posty użytkownika
Wątek zamknięty

« Starszy wątek | Nowszy wątek »
Użytkownicy przeglądający ten wątek: 1 gości


Temat został oceniony na 5 w skali 1-5 gwiazdek.
Zebrano 1 głosów.

Google
Facebook