// adds pushpins for the POI locations. The pusphins can be customised depending on the place.
        // the method also adds poi info to the listview
        private async void addPushPinAtPOIAndAddtoList(JsonSchemas.NavteqPoiSchema.Response response)
        {
            if (response != null && response.ResultSet != null &&
                response.ResultSet.Results != null &&
                response.ResultSet.Results.Length > 0)
            {
                this.Dispatcher.Invoke(() =>
                {
                    myMap.Children.Clear();
                    nearbyPlacesList.Visibility = Visibility.Visible;
                });
                foreach (var poi in response.ResultSet.Results)
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        var loc      = new Microsoft.Maps.MapControl.WPF.Location(poi.Latitude, poi.Longitude);
                        var pin      = new Pushpin();
                        pin.Tag      = poi;
                        pin.Content  = "" + StaticVariables.POINumber;
                        pin.Location = loc;
                        myMap.Children.Add(pin);
                    });
                    BitmapImage poiImage = await getImageryOfPOI(new Coordinate(poi.Latitude, poi.Longitude));

                    addPOIToListView(poiImage, poi, StaticVariables.POINumber++);
                }
            }

            else
            {
                setSystemWarningMessagesToSpeechLabel(SystemMessages.NOPOI_MESSAGE);
                System.Diagnostics.Trace.WriteLine("No result");
            }
        }
Example #2
0
        // this function processes the SHOW_NEARBY intent by resolving the location and adding Places of Interest (POI) near it.
        private async void ProcessShowNearbyIntent(LUISJsonObject luisJson)
        {
            this.WriteLine("{0}", "------------------ProcessShowNearbyIntent------------------");
            // first the map is cleared of all child elements
            this.Dispatcher.Invoke(() =>
            {
                clearMap();
            });
            // the entity whose location is to be identified
            Entity showNearbyEntity = null;
            Entity bingEntity       = null;
            // boolean for any abstract location e.g."here", "there"
            bool isAbstractLocationPresent = false;

            if (luisJson.Entities.Length > 0)
            {
                foreach (Entity entity in luisJson.Entities)
                {
                    if (entity.Type.Contains(LuisEntityTypes.PLACE))
                    {
                        showNearbyEntity = entity;
                    }
                    else if (entity.Type.Contains(LuisEntityTypes.BINGENTITYTYPE))
                    {
                        bingEntity = entity;
                    }
                    else if (entity.Type.Contains(LuisEntityTypes.ABSTRACTLOCATION))
                    {
                        isAbstractLocationPresent = true;
                    }
                }
            }
            if (null != showNearbyEntity || null != bingEntity)
            {
                int?       entityId             = null;
                Coordinate coordinateOfLocation = null;
                if (null != showNearbyEntity)
                {
                    coordinateOfLocation = await getLocationFromAddress(showNearbyEntity.EntityValue);

                    if (null == coordinateOfLocation)
                    {
                        setSystemWarningMessagesToSpeechLabel(string.Format(SystemMessages.NOLOCATION_MESSAGE, showNearbyEntity.EntityValue));
                        return;
                    }
                }

                if (null != bingEntity)
                {
                    if (StaticVariables.bingPOISearchEntityNameToEntityId.ContainsKey(bingEntity.EntityValue.ToLower()))
                    {
                        entityId = StaticVariables.bingPOISearchEntityNameToEntityId[bingEntity.EntityValue.ToLower()];
                    }
                    if (!entityId.HasValue)
                    {
                        setSystemWarningMessagesToSpeechLabel(string.Format(SystemMessages.NOENTITY_MESSAGE, bingEntity.EntityValue));
                        return;
                    }
                }

                // adds POI at the location
                if (null != coordinateOfLocation)
                {
                    if (entityId.HasValue)
                    {
                        JsonSchemas.NavteqPoiSchema.Response poiResponse = await getPOIForLocation(coordinateOfLocation.Latitude, coordinateOfLocation.Longitude, new EntityTypeFilter(entityId.Value.ToString()));

                        nearbyListHeader(bingEntity.EntityValue);
                        //  add specific places like coffee, bus stop, bar, based on enity name specified by user
                        addPushPinAtPOIAndAddtoList(poiResponse);
                        this.Dispatcher.Invoke(() =>
                        {
                            setCenterOfMap(coordinateOfLocation.Latitude, coordinateOfLocation.Longitude, 14);
                        });
                    }
                    else
                    {
                        JsonSchemas.NavteqPoiSchema.Response poiResponse = await getPOIForLocation(coordinateOfLocation.Latitude, coordinateOfLocation.Longitude);

                        nearbyListHeader("Places");
                        // finds all POI at the location
                        addPushPinAtPOIAndAddtoList(poiResponse);
                        this.Dispatcher.Invoke(() =>
                        {
                            setCenterOfMap(coordinateOfLocation.Latitude, coordinateOfLocation.Longitude, 14);
                        });
                    }
                }
                // in case location is not specified but specific POI is mentioned then POI is found at the place where the user kinect hand is pointed.
                else
                {
                    if (entityId.HasValue)
                    {
                        nearbyListHeader(bingEntity.EntityValue);
                        // if the user mentions a abstractlocation like "here" or "there"
                        if (isAbstractLocationPresent)
                        {
                            addPOIToMapFromKinectHandPosition(new EntityTypeFilter(entityId.Value.ToString()));
                        }
                        // if the user does not mention any location for finding POI then map center is taken as reference location
                        else
                        {
                            double latitude  = 0;
                            double longitude = 0;
                            this.Dispatcher.Invoke(() =>
                            {
                                Trace.WriteLine("first");
                                latitude  = myMap.Center.Latitude;
                                longitude = myMap.Center.Longitude;
                            });
                            Trace.WriteLine("first");
                            JsonSchemas.NavteqPoiSchema.Response poiResponse = await getPOIForLocation(latitude, longitude, new EntityTypeFilter(entityId.Value.ToString()));

                            addPushPinAtPOIAndAddtoList(poiResponse);
                        }
                    }
                }
            }
            // if no entities are found and SHOW_NEARBY intent is identified
            // then the POI nearby to the location where the kinect hand is pointing to is found
            else
            {
                nearbyListHeader("Places");
                addPOIToMapFromKinectHandPosition();
            }
        }