コード例 #1
0
		static async Task<IEnumerable<Position>> GetPositionsForAddress(string s)
		{
			var results = new List<Position>();

			if (string.IsNullOrEmpty(s))
				return results;

			var requestOptions = new GeocodeRequestOptions(s);
			var response =
				await new Bing.Maps.Map { Credentials = FormsMaps.AuthenticationToken }.SearchManager.GeocodeAsync(requestOptions);
			if (!response.HasError)
			{
				foreach (var address in response.LocationData)
					results.Add(new Position(address.Location.Latitude, address.Location.Longitude));
			}
			return results;
		}
コード例 #2
0
        private async void SearchPaneSuggestionsRequested(
            SearchPane sender,
            SearchPaneSuggestionsRequestedEventArgs args)
        {
            SearchPaneSuggestionsRequestDeferral deferral = args.Request.GetDeferral();

            GeocodeRequestOptions requests = new GeocodeRequestOptions(args.QueryText);

            _searchManager  = MapView.SearchManager;
            _searchResponse = await _searchManager.GeocodeAsync(requests);

            foreach (GeocodeLocation locationData in _searchResponse.LocationData)
            {
                args.Request.SearchSuggestionCollection.AppendQuerySuggestion(locationData.Address.FormattedAddress);
            }

            deferral.Complete();
        }
コード例 #3
0
        /// <summary>
        /// Creates the shop views.
        /// </summary>
        /// <param name="shops">The shops.</param>
        /// <param name="searchManager">The search manager.</param>
        /// <returns></returns>
        private async Task <List <ShopView> > createShopViews(List <Shop> shops, SearchManager searchManager)
        {
            List <ShopView> shopViews = new List <ShopView>();

            //get the location associated to all shops and create their views
            foreach (Shop shop in shops)
            {
                var options  = new GeocodeRequestOptions(shop.Address);
                var response = await searchManager.GeocodeAsync(options);

                GeocodeLocation shopLocation = null;

                if (response.LocationData.Count > 0)
                {
                    shopLocation = response.LocationData[0];
                    ShopView shopView = new ShopView(shop, shopLocation, this.Resources["PushPinMarketStyle"] as Style);
                    shopViews.Add(shopView);
                }
            }

            return(shopViews);
        }
コード例 #4
0
        static async Task <IEnumerable <Position> > GetPositionsForAddress(string s)
        {
            var results = new List <Position>();

            if (string.IsNullOrEmpty(s))
            {
                return(results);
            }

            var requestOptions = new GeocodeRequestOptions(s);
            var response       =
                await new Bing.Maps.Map {
                Credentials = FormsMaps.AuthenticationToken
            }.SearchManager.GeocodeAsync(requestOptions);

            if (!response.HasError)
            {
                foreach (var address in response.LocationData)
                {
                    results.Add(new Position(address.Location.Latitude, address.Location.Longitude));
                }
            }
            return(results);
        }
コード例 #5
0
        //Assumes the response array has been properly populated
        async void PopulateNewRestaurant()
        {
            JsonArray businesses = response.GetNamedArray("businesses");
            JsonObject business = businesses.GetObjectAt((uint)rand.Next(0, businesses.Count-1));
            JsonArray categories = business.GetNamedArray("categories");
            String categoriesStr = "";
            for (uint i = 0; i < categories.Count; i++)
            {
                JsonObject category = categories.GetObjectAt(i);
                if (categoriesStr.Length != 0)
                {
                    categoriesStr += ", ";
                }
                categoriesStr += category.GetNamedString("name");
            }

            Name.Text = business.GetNamedString("name");
            Location.Text = business.GetNamedString("address1") + "\n" + business.GetNamedString("city") + ", " + business.GetNamedString("state") + " " + business.GetNamedString("zip");
            
            string number = business.GetNamedString("phone");
            if (number != "")
            {
                Phone.Text = parsePhoneNumber(number);
            }

            Categories.Text = "Cuisine: " + categoriesStr;
            Rating_Image.Source = new BitmapImage(new Uri(business.GetNamedString("rating_img_url")));
            Image.Source = new BitmapImage(new Uri(business.GetNamedString("photo_url")));
            Url.NavigateUri = new Uri(business.GetNamedString("url"));
            bool isClosed = business.GetNamedBoolean("is_closed");
            string city = business.GetNamedString("city");
            if (city != "")
            {
                pageTitle.Text = "Restaurant near " + city;
            }

            // Restaurant is closed
            if (isClosed)
            {
                OpenClosed.Text = Name.Text + " is closed :(";
                OpenClosedImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/x.jpg"));
            }
            else // open
            {
                OpenClosed.Text = Name.Text + " is open! :)";
                OpenClosedImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/checkmark.jpg"));
            }

            Diff_Restaurant.IsEnabled = false;

            GeocodeRequestOptions requestOptions = new GeocodeRequestOptions(business.GetNamedString("address1") + " " + business.GetNamedString("city") + ", " + business.GetNamedString("state") + " " + business.GetNamedString("zip"));
            Bing.Maps.Search.SearchManager searchManager = bingMap.SearchManager;
            Bing.Maps.Search.LocationDataResponse mapResponse = await searchManager.GeocodeAsync(requestOptions);

            //Make sure we got a response back
            if (mapResponse.LocationData.Count > 0)
            {
                Bing.Maps.Location businessLocation = mapResponse.LocationData.First<GeocodeLocation>().Location;
                bingMap.Children.Clear();

                Pushpin pin = new Pushpin();
                pin.Text = Name.Text;
                MapLayer.SetPosition(pin, businessLocation);
                bingMap.Children.Add(pin);

                bingMap.SetZoomLevel(15, MapAnimationDuration.None);
                bingMap.SetView(businessLocation);
            }

            Diff_Restaurant.IsEnabled = true;

            // Url.Content = business.GetNamedString("url");
        }
コード例 #6
0
ファイル: PlaceSearch.cs プロジェクト: gminky019/BING-POI-Map
        /// <summary>
        /// gets the location only by using a place i.e. Reno as a search key
        /// </summary>
        /// <returns></returns>
        public async Task getLatLon()
        {
            LocationDataResponse responseLoc;
            try
            {
                //get the GEocode request
                GeocodeRequestOptions options = new GeocodeRequestOptions(_location._searcher);

                //get the location from the place
                responseLoc = await _location._map.SearchManager.GeocodeAsync(options);
           
                //as long as it not null set the lat amd long of the location
                if (_searches.checkNullLoc(responseLoc))
                {
                    _location._latitude = responseLoc.LocationData[0].Location.Latitude;
                    _location._longitude = responseLoc.LocationData[0].Location.Longitude;
                }
            }
            catch (Exception e)
            {
              throw new Exception("problem getting Location from key search", e);
            }

        }
コード例 #7
0
        private async void SearchPaneSuggestionsRequested(
            SearchPane sender,
            SearchPaneSuggestionsRequestedEventArgs args)
        {
            SearchPaneSuggestionsRequestDeferral deferral = args.Request.GetDeferral();

            GeocodeRequestOptions requests = new GeocodeRequestOptions(args.QueryText);
            _searchManager = MapView.SearchManager;
            _searchResponse = await _searchManager.GeocodeAsync(requests);
            foreach (GeocodeLocation locationData in _searchResponse.LocationData)
                args.Request.SearchSuggestionCollection.AppendQuerySuggestion(locationData.Address.FormattedAddress);

            deferral.Complete();
        }
コード例 #8
0
        private static async Task<IEnumerable<Position>> GetPositionsForAddressAsync(string s)
        {
            List<Position> results = new List<Position>();
#if WINDOWS_APP
            CreateSearchManager();
            GeocodeRequestOptions options = new GeocodeRequestOptions(s);
            LocationDataResponse response = await _manager.GeocodeAsync(options);
            foreach(GeocodeLocation l in response.LocationData)
            {
                results.Add(new Position(l.Location.Latitude, l.Location.Longitude));
            }
#else
            MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(s, new Windows.Devices.Geolocation.Geopoint(new Windows.Devices.Geolocation.BasicGeoposition()));
            if (result.Status == MapLocationFinderStatus.Success)
            {
                foreach (MapLocation location in result.Locations)
                {
                    if (location.Address != null)
                    {
                        results.Add(new Position(location.Point.Position.Latitude, location.Point.Position.Longitude));
                    }
                }
            }
#endif
            return results;
        }