コード例 #1
0
        /// <summary>
        /// Searches all agencies for all bus numbers.
        /// </summary>
        public async Task SearchAsync(string query, OneBusAway.Model.Point userLocation)
        {
            this.NoSearchResultsText = string.Format(CultureInfo.CurrentCulture, "SEARCHING FOR '{0}'", query);

            try
            {
                if (string.IsNullOrEmpty(query))
                {
                    this.SearchResults.Clear();
                    this.BingMapsSearchResults = null;
                }
                else
                {
                    // If the user selected a suggestion, then that means they want a specific bus:
                    if (query.StartsWith("BUS", StringComparison.OrdinalIgnoreCase))
                    {
                        await DisplayAndSelectSpecificRouteAsync(query.Substring(3).Trim());
                    }
                    else
                    {
                        var listOfAllRoutes = await this.LoadAllRoutesAsync();

                        // Let's filter the results!

                        var newItems = (from result in listOfAllRoutes
                                        where (result.ShortName != null && result.ShortName.IndexOf(query, StringComparison.OrdinalIgnoreCase) > -1) ||
                                        (result.Description != null && result.Description.IndexOf(query, StringComparison.OrdinalIgnoreCase) > -1)
                                        select new SearchRouteResultViewModel(result));

                        await this.uiHelper.BatchAddItemsAsync(this.searchResults, newItems);

                        var bingMapResults = await BingMapsServiceHelper.GetLocationByQuery(query, Utilities.Confidence.Medium, userLocation);

                        this.BingMapsSearchResults = (from result in bingMapResults
                                                      select new SearchLocationResultViewModel(result)).ToArray();
                    }
                }
            }
            catch
            {
            }

            this.NoSearchResultsText = "NO RESULTS";
        }
コード例 #2
0
        /// <summary>
        /// Creates a map image for a tile.
        /// </summary>
        private static async Task <string> CreateTileMapImageAsync(string tileId, double latitude, double longitude, int width, int height, TileSize tileSize)
        {
            // Get the image from Bing and save to disk.
            string tileImageFile = string.Format("{0}-{1}.png", tileId, tileSize.ToString());
            string tileImagePath = Path.Combine("Tiles", tileImageFile);

            bool fileExists = false;

            try
            {
                var file = await ApplicationData.Current.LocalFolder.GetFileAsync(tileImagePath);

                fileExists = true;
            }
            catch
            {
            }

            // Create the file:
            if (!fileExists)
            {
                BingMapsServiceHelper bingMapsHelper = new BingMapsServiceHelper();
                using (var memoryStream = await bingMapsHelper.GetStaticImageBytesAsync(
                           latitude,
                           longitude,
                           width,
                           height))
                {
                    IStorageFile storageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(tileImagePath, CreationCollisionOption.ReplaceExisting);

                    using (var stream = await storageFile.OpenStreamForWriteAsync())
                    {
                        memoryStream.WriteTo(stream);
                    }
                }
            }

            return(tileImageFile);
        }