async Task findLocationAsync(String location)
        {
            if (String.IsNullOrEmpty(location) || String.IsNullOrWhiteSpace(location))
            {
                clear();
                return;
            }

            LocationRect usermapView = null;

            if (GeoLocationRect != null)
            {
                usermapView = map.BoundingRectangle;
            }

            Task <List <LocationResult> > t = Task.Factory.StartNew <List <LocationResult> >(() =>
            {
                return(BingMapsService.findLocations(location, BingMapsKey.SessionKey, usermapView));
            });

            try
            {
                findLocationButton.IsEnabled   = false;
                findLocationComboBox.IsEnabled = false;

                await t;

                if (t.Result.Count > 0)
                {
                    findLocationComboBox.ItemsSource   = t.Result;
                    findLocationComboBox.SelectedIndex = 0;
                }
                else
                {
                    findLocationComboBox.ItemsSource = null;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error searching location\n\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                findLocationButton.IsEnabled   = true;
                findLocationComboBox.IsEnabled = true;
            }
        }
Ejemplo n.º 2
0
 internal bool QueryVirtualEarthService(bool asyncQuery)
 {
     if (string.IsNullOrEmpty(Common.MapCore.TileServerAppId) || Common.MapCore.TileServerAppId.ToUpper(CultureInfo.InvariantCulture) == "(DEFAULT)")
     {
         lock (TileError)
         {
             TileError = SR.ProvideBingMapsAppID;
         }
         return(false);
     }
     try
     {
         ImageryMetadataRequest imageryRequest = new ImageryMetadataRequest
         {
             BingMapsKey             = common.MapCore.TileServerAppId,
             ImagerySet              = VirtualEarthTileSystem.TileSystemToMapStyle(TileSystem),
             IncludeImageryProviders = true,
             UseHTTPS = true
         };
         if (asyncQuery)
         {
             BingMapsService.GetImageryMetadataAsync(imageryRequest, ProcessImageryMetadataResponse, delegate(Exception ex)
             {
                 lock (TileError)
                 {
                     TileError = ex.Message;
                 }
             });
         }
         else
         {
             Response imageryMetadata = BingMapsService.GetImageryMetadata(imageryRequest);
             ProcessImageryMetadataResponse(imageryMetadata);
         }
     }
     catch (Exception ex2)
     {
         lock (TileError)
         {
             TileError = ex2.Message;
         }
         return(false);
     }
     return(true);
 }
Ejemplo n.º 3
0
 public bool QueryVirtualEarthService(bool asyncQuery)
 {
     if (!string.IsNullOrEmpty(this.Common.MapCore.TileServerAppId) && !(this.Common.MapCore.TileServerAppId.ToUpper(CultureInfo.InvariantCulture) == "(DEFAULT)"))
     {
         try
         {
             ImageryMetadataRequest imageryMetadataRequest = new ImageryMetadataRequest();
             imageryMetadataRequest.BingMapsKey             = base.common.MapCore.TileServerAppId;
             imageryMetadataRequest.ImagerySet              = VirtualEarthTileSystem.TileSystemToMapStyle(this.TileSystem);
             imageryMetadataRequest.IncludeImageryProviders = true;
             imageryMetadataRequest.UseHTTPS = true;
             ImageryMetadataRequest imageryRequest = imageryMetadataRequest;
             if (asyncQuery)
             {
                 BingMapsService.GetImageryMetadataAsync(imageryRequest, this.ProcessImageryMetadataResponse, delegate(Exception ex)
                 {
                     lock (this.TileError)
                     {
                         this.TileError = ex.Message;
                     }
                 });
             }
             else
             {
                 Response imageryMetadata = BingMapsService.GetImageryMetadata(imageryRequest);
                 this.ProcessImageryMetadataResponse(imageryMetadata);
             }
         }
         catch (Exception ex2)
         {
             lock (this.TileError)
             {
                 this.TileError = ex2.Message;
             }
             return(false);
         }
         return(true);
     }
     lock (this.TileError)
     {
         this.TileError = SR.ProvideBingMapsAppID;
     }
     return(false);
 }
        private static void OnGeocodeResultChanged(Map map, BingMapsService.GeocodeResult oldValue, BingMapsService.GeocodeResult newValue)
        {
            Location location = newValue.Locations.Select(x => new Location(x.Latitude, x.Longitude)).First();

            Pushpin pin = new Pushpin();
            pin.Location = location;
            pin.ToolTip = newValue.Address.FormattedAddress;

            var locationLayer = GetGeocodeResultLayer(map);
            if (locationLayer == null)
            {
                locationLayer = new MapLayer();
                SetGeocodeResultLayer(map, locationLayer);
            }

            locationLayer.Children.Clear();
            locationLayer.Children.Add(pin);

            map.SetView(location, map.ZoomLevel);
        }
 public BingLocationService(string bingMapsKey)
 {
     this.service = new BingMapsService(bingMapsKey);
 }
 public static void SetGeocodeResult(Map target, BingMapsService.GeocodeResult value)
 {
     target.SetValue(GeocodeResultProperty, value);
 }