如何在android谷歌地图上按标题搜索标记

时间:2016-10-24 06:31:43

标签: android json google-maps

我正在使用json从网络服务中检索标记,我想使用标记属性标题在地图上搜索它们

这是java代码:

using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Linq;

namespace WpfStackOverflow.Controls
{
    /// <summary>
    /// Interaction logic for MenuOpenOnlyOnClick.xaml
    /// </summary>
    public partial class MenuOpenOnlyOnClick : Menu
    {
        public MenuOpenOnlyOnClick()
        {
            InitializeComponent();            
        }

        protected override DependencyObject GetContainerForItemOverride()
        {
            return new MenuItemNew();
        }
    }

    public class MenuItemNew : MenuItem
    {
        #region Constructors
        static MenuItemNew()
        {
            MenuItem.IsSubmenuOpenProperty.OverrideMetadata(typeof(MenuItemNew),
                new FrameworkPropertyMetadata(false, MenuItem.IsSubmenuOpenProperty.DefaultMetadata.PropertyChangedCallback, CoerceIsSubmenuOpen));
        }

        public MenuItemNew()
        {
            this.PreviewMouseLeftButtonDown += MenuItemNew_PreviewMouseLeftButtonDown;
            this.LostFocus += MenuItemNew_LostFocus;
        }
        #endregion

        #region Event Handlers
        void MenuItemNew_LostFocus(object sender, RoutedEventArgs e)
        {
            MenuItemNew item = sender as MenuItemNew;
            item.IsMenuItemExpanded = false;
        }

        void MenuItemNew_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            MenuItemNew item = sender as MenuItemNew;

            if (item.Role == MenuItemRole.SubmenuHeader)
            {
                IsMenuItemExpanded = !IsMenuItemExpanded;
                IsSubmenuOpen = IsMenuItemExpanded;
            }
        }
        #endregion

        #region IsMenuItemExpanded Dependency Property

        public bool IsMenuItemExpanded
        {
            get { return (bool)GetValue(IsExpanderClickedProperty); }
            set { SetValue(IsExpanderClickedProperty, value); }
        }

        // Using a DependencyProperty as the backing store for IsMenuItemExpanded.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsExpanderClickedProperty =
            DependencyProperty.Register("IsMenuItemExpanded", typeof(bool), typeof(MenuItemNew),
            new PropertyMetadata(false, null));

        #endregion

        #region Overrides
        protected override DependencyObject GetContainerForItemOverride()
        {
            return new MenuItemNew();
        }
        #endregion

        #region Dependency Property Callbacks
        private static object CoerceIsSubmenuOpen(DependencyObject d, object value)
        {
            if ((bool)value)
            {
                MenuItemNew item = (MenuItemNew)d;

                if (item.Role == MenuItemRole.SubmenuHeader)
                {
                    if (item.IsMenuItemExpanded)
                        return true;
                    else
                        return false;
                }                

                if (!item.IsLoaded)
                {
                    item.Loaded += (s, e) =>
                    {
                        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new DispatcherOperationCallback(delegate(object param)
                        {
                            item.CoerceValue(MenuItemNew.IsSubmenuOpenProperty);
                            return null;
                        }), null);
                    };
                    return false;
                }
            }
            return value;
        }
        #endregion  
    }
}

这是xml

<Window x:Class="WpfStackOverflow.Window17"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ctrl="clr-namespace:WpfStackOverflow.Controls"
        Title="Window17" Height="300" Width="300">

    <Grid>
        <ctrl:MenuOpenOnlyOnClick VerticalAlignment="Top" >
            <ctrl:MenuItemNew Header="File">
                <ctrl:MenuItemNew Header="New">
                    <ctrl:MenuItemNew Header="Project"/>
                    <ctrl:MenuItemNew Header="Website"/>
                </ctrl:MenuItemNew>
                <ctrl:MenuItemNew Header="Open"/>
            </ctrl:MenuItemNew>
        </ctrl:MenuOpenOnlyOnClick>
    </Grid>

</Window>

非常感谢任何帮助。

0 个答案:

没有答案