public static void ReverseGeocodeAddress(Dispatcher uiDispatcher, CredentialsProvider credentialsProvider, Location location, Action<GeocodeResult> completed = null, Action<GeocodeError> error = null)
        {
            completed = completed ?? (r => { });
            error = error ?? (e => { });

            // Get credentials and only then place an async call on the geocode service.
            credentialsProvider.GetCredentials(credentials =>
            {
                var request = new ReverseGeocodeRequest()
                {
                    // Pass in credentials for web services call.
                    Credentials = credentials,

                    Culture = CultureInfo.CurrentUICulture.Name,
                    Location = location,

                    // Don't raise exceptions.
                    ExecutionOptions = new UsingBingMaps.Bing.Geocode.ExecutionOptions
                    {
                        SuppressFaults = true
                    },
                };

 

                EventHandler<ReverseGeocodeCompletedEventArgs> reverseGeocodeCompleted = (s, e) =>
                {
                    try
                    {
                        if (e.Result.ResponseSummary.StatusCode != UsingBingMaps.Bing.Geocode.ResponseStatusCode.Success ||
                            e.Result.Results.Count == 0)
                        {
                            // Report geocode error.
                            uiDispatcher.BeginInvoke(() => error(new GeocodeError(e)));
                        }
                        else
                        {
                            // Only report on first result.
                            var firstResult = e.Result.Results.First();
                            uiDispatcher.BeginInvoke(() => completed(firstResult));
                            Debug.WriteLine("street=" + firstResult.Address.AddressLine.ToString());
                            Debug.WriteLine("admin district=" + firstResult.Address.AdminDistrict.ToString());
                            Debug.WriteLine("country region=" + firstResult.Address.CountryRegion.ToString());
                            Debug.WriteLine("district=" + firstResult.Address.District.ToString());
                            Debug.WriteLine("formatted addres=" + firstResult.Address.FormattedAddress.ToString());
                            Debug.WriteLine("locality=" + firstResult.Address.Locality.ToString());
                            Debug.WriteLine("postal code=" + firstResult.Address.PostalCode.ToString());
                            Debug.WriteLine("postal town=" + firstResult.Address.PostalTown.ToString());
                            CurrentAddress = firstResult.Address.FormattedAddress.ToString();
                            CurrentAddress_AdminDistrict = firstResult.Address.AdminDistrict.ToString();
                            CurrentAddress_CountryRegion = firstResult.Address.CountryRegion.ToString();
                            CurrentAddress_Locality = firstResult.Address.Locality.ToString();
                            CurrentAddress_PostalCode = firstResult.Address.PostalCode.ToString();
                            CurrentAddress_AddressLine = firstResult.Address.AddressLine.ToString();
                        }
                    }
                    catch (Exception ex)
                    {
                        uiDispatcher.BeginInvoke(() => error(new GeocodeError(ex.Message, ex)));
                    }
                };

                var geocodeClient = new GeocodeServiceClient();
                geocodeClient.ReverseGeocodeCompleted += reverseGeocodeCompleted;
                geocodeClient.ReverseGeocodeAsync(request);
            });
        }
        private void CalculateRouteByLocation(Location from, Location to)
        {
            Debug.WriteLine("CalculateRouteByLocation");
                var routeCalculator = new RouteCalculator(
                    CredentialsProvider,
                    to, from,
                    Dispatcher,
                    result =>
                    {
                        // Clear the route collection to have only one route at a time.
                        Routes.Clear();

                        // Clear previous route related itineraries.
                        Settings.Itinerary= new ObservableCollection<ItineraryItem>();

                        // Create a new route based on route calculator result,
                        // and add the new route to the route collection.
                        var routeModel = new RouteModel(result.Result.RoutePath.Points);
                        Routes.Add(routeModel);

                        // Add new route itineraries to the itineraries collection.
                        foreach (var itineraryItem in result.Result.Legs[0].Itinerary)
                        {
                            Settings.Itinerary.Add(itineraryItem);
                        }

                        // Set the map to center on the new route.
                        var viewRect = LocationRect.CreateLocationRect(routeModel.Locations);
                        Map.SetView(viewRect);                        
                        //ShowDirectionsView();
                    });

                // Display an error message in case of fault.
                routeCalculator.Error += r => MessageBox.Show(r.Reason);

                // Start the route calculation asynchronously.
                routeCalculator.CalculateAsync();
        }
        private void findMyCar()
        {
                Debug.WriteLine("findMyCar");
                bool exist = false;
                Location g_from = new Location();
                g_from.Latitude = MyLocation.Y;
                g_from.Longitude = MyLocation.X;
                Location g_to = new Location();

                for (int i = 0; i < Table.Count(); i++)
                {
                    if (Table[i].Type == "Car Locator")
                    {
                        g_to.Longitude = Table[i].longitude;
                        g_to.Latitude = Table[i].latitude;
                        exist = true;
                        break;
                    }
                }
                if (exist == true)
                {
                    show_route = true;
                    CalculateRouteByLocation(g_from, g_to);
                }
                else
                {
                    MessageBox.Show("Please set the location of your car.");
                }
        }