Исключение при отслеживании местоположения в Windows Phone 8

Когда я пытаюсь отследить местоположение, он работает отлично, но когда я добавляю к нему ссылку на службу, он выдает исключение, когда я пробую ту же программу без добавления местоположения, только добавляю ссылку на службу, она работает отлично. Мой код здесь ниже, а копия из Как постоянно отслеживать местоположение телефона для Windows Phone 8< /а>

public partial class MainPage : PhoneApplicationPage
{

    Geolocator geolocator = null;
    bool tracking = false;
    ServiceReference2.GetPositionClient client = new ServiceReference2.GetPositionClient();
    // Constructor
    public MainPage()
    {
        InitializeComponent();

        // Sample code to localize the ApplicationBar
        //BuildLocalizedApplicationBar();
    }
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
        {
            // User has opted in or out of Location
            return;
        }
        else
        {
            MessageBoxResult result =
                MessageBox.Show("This app accesses your phone's location. Is that ok?",
                "Location",
                MessageBoxButton.OKCancel);

            if (result == MessageBoxResult.OK)
            {
                IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
            }
            else
            {
                IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
            }

            IsolatedStorageSettings.ApplicationSettings.Save();
        }
    }
    private void TrackLocation_Click(object sender, RoutedEventArgs e)
    {
        if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] != true)
        {
            // The user has opted out of Location.
            return;
        }

        if (!tracking)
        {
            geolocator = new Geolocator();
            geolocator.DesiredAccuracy = PositionAccuracy.High;
            geolocator.MovementThreshold = 100; // The units are meters.

            geolocator.StatusChanged += geolocator_StatusChanged;
            geolocator.PositionChanged += geolocator_PositionChanged;

            tracking = true;
            TrackLocationButton.Content = "stop tracking";
        }
        else
        {
            geolocator.PositionChanged -= geolocator_PositionChanged;
            geolocator.StatusChanged -= geolocator_StatusChanged;
            geolocator = null;

            tracking = false;
            TrackLocationButton.Content = "track location";
            StatusTextBlock.Text = "stopped";
        }
    }
    void geolocator_StatusChanged(Geolocator sender, StatusChangedEventArgs args)
    {
        string status = "";

        switch (args.Status)
        {
            case PositionStatus.Disabled:
                // the application does not have the right capability or the location master switch is off
                status = "location is disabled in phone settings";
                break;
            case PositionStatus.Initializing:
                // the geolocator started the tracking operation
                status = "initializing";
                break;
            case PositionStatus.NoData:
                // the location service was not able to acquire the location
                status = "no data";
                break;
            case PositionStatus.Ready:
                // the location service is generating geopositions as specified by the tracking parameters
                status = "ready";
                break;
            case PositionStatus.NotAvailable:
                status = "not available";
                // not used in WindowsPhone, Windows desktop uses this value to signal that there is no hardware capable to acquire location information
                break;
            case PositionStatus.NotInitialized:
                // the initial state of the geolocator, once the tracking operation is stopped by the user the geolocator moves back to this state

                break;
        }

        Dispatcher.BeginInvoke(() =>
        {
            StatusTextBlock.Text = status;
        });
    }





    void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
    {
        client.getPosCompleted += new EventHandler<ServiceReference2.getPosCompletedEventArgs>(sendData);

        client.getPosAsync(11,11);


        Dispatcher.BeginInvoke(() =>
        {
            LatitudeTextBlock.Text = args.Position.Coordinate.Latitude.ToString("0.00");
            LongitudeTextBlock.Text = args.Position.Coordinate.Longitude.ToString("0.00");
        });
    }


    public void sendData(object sender, ServiceReference2.getPosCompletedEventArgs e)
    {

        dd.Text = e.Result;

    }
    }

person zkn    schedule 11.09.2013    source источник
comment
какое исключение выдает?   -  person Malachi    schedule 12.09.2013


Ответы (2)


у тебя есть

client.getPosCompleted += new EventHandler<ServiceReference2.getPosCompletedEventArgs>(sendData);

но вы нигде больше не давали клиенту никаких значений, я предполагаю, что вы получаете исключение null Reference, и именно поэтому.

person Malachi    schedule 11.09.2013
comment
client.getPosCompleted += новый EventHandler‹ServiceReference2.getPosCompletedEventArgs›(sendData); клиент.getPosAsync(11,11); - person zkn; 07.11.2013
comment
я использую это ... у меня есть исключение, что удаленный сервер вернул ошибку: не найден .. - person zkn; 07.11.2013
comment
пожалуйста, добавьте это исключение в вопрос, чтобы мы могли лучше устранить проблему. - person Malachi; 07.11.2013
comment
это только что решило это просто ошибка настройки iis, потому что мобильный телефон и компьютер находятся в разных сетях, поэтому связь невозможна. Я просто перенаправляю порт в настройках маршрутизатора - person zkn; 08.01.2014

Это только что решило это, просто ошибка настройки IIS, потому что мобильный телефон и компьютер находятся в разных сетях, поэтому связь невозможна. Я просто перенаправляю порт в настройках маршрутизатора -

person zkn    schedule 08.09.2015