private async void Control2_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
        {
            var select = (args.SelectedItem as PlaceAutoComplete.Prediction);

            if (select == null)
            {
                return;
            }
            var res = await GeocodeHelper.GetInfo(select.place_id);

            SearchBox.Text = "";
            if (res == null || res.results.Length == 0)
            {
                await new MessageDialog("We couldn't find place location!").ShowAsync();
                return;
            }
            var ploc = res.results.FirstOrDefault().geometry.location;

            MapView.MapControl.Center = new Geopoint(
                new BasicGeoposition()
            {
                Latitude  = ploc.lat,
                Longitude = ploc.lng
            });
            MapView.StaticMapView.SearchResultPoint = new Geopoint(
                new BasicGeoposition()
            {
                Latitude  = ploc.lat,
                Longitude = ploc.lng
            });
            (DataContext as ViewModel).SearchResults.Clear();
            //SearchReq.Invoke(args.SelectedItem as ClassProduct.Product, null);
            //SearchBox.Visibility = Visibility.Collapsed;
            //BTNExpand.Visibility = Visibility.Visible;
        }
        private async void ListView_ItemClick(object sender, ItemClickEventArgs e)
        {
            var select = e.ClickedItem as PlaceAutoComplete.Prediction;

            if (select == null)
            {
                return;
            }
            var res = await GeocodeHelper.GetInfo(select.place_id);

            if (res == null)
            {
                return;
            }
            var ploc = res.results.FirstOrDefault().geometry.location;

            MapView.MapControl.Center = new Geopoint(
                new BasicGeoposition()
            {
                Latitude  = ploc.lat,
                Longitude = ploc.lng
            });
            MapView.StaticMapView.SearchResultPoint = new Geopoint(
                new BasicGeoposition()
            {
                Latitude  = ploc.lat,
                Longitude = ploc.lng
            });
            MapView.StaticSearchGrid.PopUP = false;
        }
        private async void Control2_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
        {
            var select = (args.SelectedItem as PlaceAutoComplete.Prediction);

            if (select == null)
            {
                return;
            }
            var res = await GeocodeHelper.GetInfo(select.place_id);

            if (res == null)
            {
                return;
            }
            SearchBox.Text = "";
            var ploc = res.results.FirstOrDefault().geometry.location;

            MapView.MapControl.Center = new Geopoint(
                new BasicGeoposition()
            {
                Latitude  = ploc.lat,
                Longitude = ploc.lng
            });
            //SearchReq.Invoke(args.SelectedItem as ClassProduct.Product, null);
            SearchBox.Visibility = Visibility.Collapsed;
            BTNExpand.Visibility = Visibility.Visible;
        }
Beispiel #4
0
        private async void OriginTxt_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
        {
            var pre = args.SelectedItem as PlaceAutoComplete.Prediction;

            if (pre == null)
            {
                return;
            }
            sender.Text = pre.description;

            if (pre.description == "MyLocation")
            {
                if (sender.Name == "OriginTxt")
                {
                    var p = (await ViewModel.MapViewVM.GeoLocate.GetGeopositionAsync()).Coordinate.Point;
                    DirectionsMainUserControl.Origin = p;
                    DirectionsMainUserControl.AddPointer(p, "Origin");
                }
                else if (sender.Name == "DestTxt")
                {
                    var p = (await ViewModel.MapViewVM.GeoLocate.GetGeopositionAsync()).Coordinate.Point;
                    DirectionsMainUserControl.Destination = p;
                    DirectionsMainUserControl.AddPointer(p, "Destination");
                }
                else
                {
                    var index = sender.Name.Replace("WayPoint", string.Empty);
                    DirectionsMainUserControl.WayPoints[Convert.ToInt32(index)] = (await ViewModel.MapViewVM.GeoLocate.GetGeopositionAsync()).Coordinate.Point;
                }
            }
            else if (pre.description.StartsWith("Saved:"))
            {
                var savedplaces = SavedPlacesVM.GetSavedPlaces();
                var res         = savedplaces.Where(x => x.PlaceName == pre.description.Replace("Saved:", string.Empty)).FirstOrDefault();
                if (sender.Name == "OriginTxt")
                {
                    var p = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = res.Latitude, Longitude = res.Longitude
                    });
                    DirectionsMainUserControl.Origin = p;
                    DirectionsMainUserControl.AddPointer(p, "Origin");
                }
                else if (sender.Name == "DestTxt")
                {
                    var p = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = res.Latitude, Longitude = res.Longitude
                    });
                    DirectionsMainUserControl.Destination = p;
                    DirectionsMainUserControl.AddPointer(p, "Destination");
                }
                else
                {
                    var index = sender.Name.Replace("WayPoint", string.Empty);
                    DirectionsMainUserControl.WayPoints[Convert.ToInt32(index)] = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = res.Latitude, Longitude = res.Longitude
                    });
                }
            }
            else
            {
                var res = await GeocodeHelper.GetInfo(pre.place_id);

                if (res == null)
                {
                    return;
                }
                var ploc = res.results.FirstOrDefault().geometry.location;
                if (sender.Name == "OriginTxt")
                {
                    var p = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = ploc.lat, Longitude = ploc.lng
                    });
                    DirectionsMainUserControl.Origin = p;
                    DirectionsMainUserControl.AddPointer(p, "Origin");
                }
                else if (sender.Name == "DestTxt")
                {
                    var p = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = ploc.lat, Longitude = ploc.lng
                    });
                    DirectionsMainUserControl.Destination = p;
                    DirectionsMainUserControl.AddPointer(p, "Destination");
                }
                else
                {
                    var index = sender.Name.Replace("WayPoint", string.Empty);
                    DirectionsMainUserControl.WayPoints[Convert.ToInt32(index)] = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = ploc.lat, Longitude = ploc.lng
                    });
                }
            }
        }
        private async void Control2_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
        {
            var select = (args.SelectedItem as PlaceAutoComplete.Prediction);

            if (select == null)
            {
                return;
            }
            if (select.description.StartsWith("Saved:"))
            {
                SearchBox.Text = "";
                var loc = select.place_id.Split(',');
                var lat = loc[0]; var lng = loc[1];
                MapView.MapControl.Center = new Geopoint(
                    new BasicGeoposition()
                {
                    Latitude  = Convert.ToDouble(lat),
                    Longitude = Convert.ToDouble(lng)
                });
                MapView.StaticMapView.SearchResultPoint = new Geopoint(
                    new BasicGeoposition()
                {
                    Latitude  = Convert.ToDouble(lat),
                    Longitude = Convert.ToDouble(lng)
                });
                (DataContext as ViewModel).SearchResults.Clear();
                SearchBox.Text = "";
                return;
            }
            if (select.description.StartsWith("Contacts:"))
            {
                var Addres = await SearchHelper.TextSearch(select.place_id);

                if (Addres != null)
                {
                    if (Addres.results != null && Addres.results.Any())
                    {
                        var loc = Addres.results.FirstOrDefault().geometry.location;
                        MapView.MapControl.Center = new Geopoint(
                            new BasicGeoposition()
                        {
                            Latitude  = loc.lat,
                            Longitude = loc.lng
                        });
                        MapView.StaticMapView.SearchResultPoint = new Geopoint(
                            new BasicGeoposition()
                        {
                            Latitude  = loc.lat,
                            Longitude = loc.lng
                        });
                        (DataContext as ViewModel).SearchResults.Clear();
                        SearchBox.Text = "";
                    }
                }
                return;
            }
            var res = await GeocodeHelper.GetInfo(select.place_id);

            SearchBox.Text = "";
            if (res == null || res.results.Length == 0)
            {
                await new MessageDialog("We couldn't find place location!").ShowAsync();
                return;
            }
            var ploc = res.results.FirstOrDefault().geometry.location;

            MapView.MapControl.Center = new Geopoint(
                new BasicGeoposition()
            {
                Latitude  = ploc.lat,
                Longitude = ploc.lng
            });
            MapView.StaticMapView.SearchResultPoint = new Geopoint(
                new BasicGeoposition()
            {
                Latitude  = ploc.lat,
                Longitude = ploc.lng
            });
            (DataContext as ViewModel).SearchResults.Clear();
            //SearchReq.Invoke(args.SelectedItem as ClassProduct.Product, null);
            //SearchBox.Visibility = Visibility.Collapsed;
            //BTNExpand.Visibility = Visibility.Visible;
        }
Beispiel #6
0
        private async void RunMapRightTapped(MapControl sender, Geopoint Location)
        {
            InfoPane.IsPaneOpen = true;
            LastRightTap        = Location;
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
            {
                var t = (await ViewModel.PlaceControls.SearchHelper.NearbySearch(Location.Position, 5));
                if (t != null)
                {
                    var pic = t.results.Where(x => LastRightTap.DistanceTo(new Geopoint(new BasicGeoposition()
                    {
                        Latitude = x.geometry.location.lat, Longitude = x.geometry.location.lng
                    })) < 1)
                              .OrderBy(x => LastRightTap.DistanceTo(new Geopoint(new BasicGeoposition()
                    {
                        Latitude = x.geometry.location.lat, Longitude = x.geometry.location.lng
                    }))).FirstOrDefault();
                    //var pic = t.results.Where(x => x.photos != null).LastOrDefault();
                    if (pic != null)
                    {
                        LastPlaceID = pic.place_id;
                        if (pic.photos != null)
                        {
                            PlaceImage.Source = new BitmapImage()
                            {
                                UriSource = ViewModel.PhotoControls.PhotosHelper.GetPhotoUri(pic.photos.FirstOrDefault().photo_reference, 350, 350)
                            };
                        }
                        var det = await ViewModel.PlaceControls.PlaceDetailsHelper.GetPlaceDetails(pic.place_id);
                        if (det != null)
                        {
                            PlaceAddress.Text = det.result.formatted_address;
                            PlaceName.Text    = det.result.name;
                            if (det.result.formatted_phone_number != null)
                            {
                                PlacePhone.Text          = det.result.formatted_phone_number;
                                PlacePhoneItem.IsEnabled = true;
                            }
                            if (det.result.website != null)
                            {
                                PlaceWebSite.Text          = det.result.website;
                                PlaceWebSiteItem.IsEnabled = true;
                            }
                            if (det.result.opening_hours != null)
                            {
                                var hours    = det.result.opening_hours.weekday_text;
                                string MyStr = "Is open : " + det.result.opening_hours.open_now;
                                if (hours != null)
                                {
                                    foreach (var item in hours)
                                    {
                                        MyStr += Environment.NewLine + item;
                                    }
                                }
                                PlaceOpenNow.Text          = MyStr;
                                PlaceOpenNowItem.IsEnabled = true;
                            }
                            PlaceRate.Text          = det.result.rating.ToString();
                            PlaceRateItem.IsEnabled = true;
                            if (det.result.reviews != null)
                            {
                                PlaceReviewsItem.ItemsSource = det.result.reviews;
                                PlaceReviewsItem.IsEnabled   = true;
                            }
                        }
                        else
                        {
                            PlaceName.Text    = pic.name;
                            PlaceAddress.Text = pic.vicinity;
                        }
                    }
                    //else
                    //{
                    //    var res = (await GeocodeHelper.GetInfo(Location)).results.FirstOrDefault();
                    //    if (res != null)
                    //    {
                    //        PlaceName.Text = res.address_components.FirstOrDefault().short_name;
                    //        PlaceAddress.Text = res.formatted_address;
                    //    }
                    //    else
                    //    {
                    //        await new MessageDialog("We didn't find anything here. Maybe an internet connection issue.").ShowAsync();
                    //        InfoPane.IsPaneOpen = false;
                    //    }
                    //}
                }
                else
                {
                    await new MessageDialog("We didn't find anything here. Maybe an internet connection issue.").ShowAsync();
                    InfoPane.IsPaneOpen = false;
                    return;

                    var r1 = (await GeocodeHelper.GetInfo(Location));
                    if (r1 != null)
                    {
                        var res = r1.results.FirstOrDefault();
                        if (res != null)
                        {
                            PlaceName.Text    = res.address_components.FirstOrDefault().short_name;
                            PlaceAddress.Text = res.formatted_address;
                        }
                        else
                        {
                            await new MessageDialog("We didn't find anything here. Maybe an internet connection issue.").ShowAsync();
                            InfoPane.IsPaneOpen = false;
                        }
                    }
                    else
                    {
                        await new MessageDialog("We didn't find anything here. Maybe an internet connection issue.").ShowAsync();
                        InfoPane.IsPaneOpen = false;
                    }
                }
            });
        }