Exemplo n.º 1
0
        private async void SearchKeyWordCallBack(SearchSuggestModel searchSuggestModel)
        {
            try
            {
                if (!string.IsNullOrEmpty(searchSuggestModel?.KeyWords))
                {
                    _searchEntry.Text = searchSuggestModel.KeyWords;

                    var location = await SearchPOI(searchSuggestModel);

                    if (location != null)
                    {
                        await Task.Run(async() =>
                        {
                            await Task.Delay(800);

                            //Device.BeginInvokeOnMainThread(() =>
                            //{
                            _hybirdWeb.InvokeJsFunction("addMarker", null, location.Lng, location.Lat);
                            //});
                        });
                    }

                    //弹出门牌号输入
                    _registerEntry = new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal
                    };

                    _houseNumber = new Entry
                    {
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        BackgroundColor   = Color.White,
                        Placeholder       = "楼号/门牌号"
                    };

                    var button = new Button
                    {
                        Text = "确定",
                        HorizontalOptions = LayoutOptions.End,
                        Command           = new RelayCommand(CallBack)
                    };

                    _registerEntry.Children.Add(_houseNumber);
                    _registerEntry.Children.Add(button);

                    _absoluteLayout.Children.Add(_registerEntry,
                                                 new Rectangle(20, 35 + 15 + _searchEntry.Height, DeviceInfo.Width - 40, AbsoluteLayout.AutoSize));
                }
                else
                {
                    _searchEntry.Text = string.Empty;

                    _hybirdWeb.InvokeJsFunction("clearMarker", null, null);

                    if (_registerEntry != null)
                    {
                        _registerEntry.IsVisible = false;
                        _absoluteLayout.Children.Remove(_registerEntry);
                        _registerEntry = null;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }