之检索地理地点

By admin in 亚洲必赢app在哪下载 on 2019年3月13日

GeocodeService服务用来寻觅地理地点

效益如图

亚洲必赢app在哪下载 1

壹 、添加服务引用

GeocodeService服务也是WCF服务,地址是http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc

二、实例

1. public class ChinaTileSource
    {
        /// <summary>
        /// 加载中华夏族民共和国地图系统
        ///
http://r2.tiles.ditu.live.com/tiles/r%7Bquadkey%7D.png?g=41华夏地图系统
        /// </summary>
        /// <returns>TileSource</returns>
        public TileSource GetChinaTileSource()
        {
            UriBuilder tileSourceUri = new
UriBuilder(“http://r2.tiles.ditu.live.com/tiles/r%7Bquadkey%7D.png?g=41“);

            MapTileLayer tileLayer = new MapTileLayer();
            LocationRectTileSource tileSource = new
LocationRectTileSource(tileSourceUri.Uri.ToString()
               , new LocationRect(new Location(60, 60), new Location(13,
140)), new Range<double>(1, 16));
            return tileSource;
        }
    }

 

2.前台

<UserControl x:Class=”SlBindMapDemo.GeocodeServiceDemo”
   
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml
    xmlns:d=”http://schemas.microsoft.com/expression/blend/2008
   
xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006
            
xmlns:map=”clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl”
    mc:Ignorable=”d”
    d:DesignHeight=”300″ d:DesignWidth=”400″>

    <Grid x:Name=”LayoutRoot” Width=”500″ Height=”400″>
        <map:Map
CredentialsProvider=”AkGGA_JlwP7XGV8JxIPb8oEWxrInlLMGKpCe7QM4QB5cg4UGNCqUyjqVfC0B2-XC”
x:Name=”myMap”></map:Map>
        <StackPanel VerticalAlignment=”Top”
HorizontalAlignment=”Right” Background=”Gray” Opacity=”0.78″
Orientation=”Vertical” Margin=”2,23,2,2″>
            <StackPanel Orientation=”Horizontal”>
                <TextBlock Text=”地名:”
Margin=”0,5,0,5″></TextBlock>
                <TextBox x:Name=”tbName”
Width=”233″></TextBox>
                <Button x:Name=”btnQuery” Content=”搜索”
Click=”btnQuery_Click” Width=”80″ Height=”30″></Button>
            </StackPanel>
            <StackPanel Orientation=”Horizontal”>
                <TextBlock Text=”经度:”></TextBlock>
                <TextBox x:Name=”tbLongitude”
Width=”110″></TextBox>
                <TextBlock Text=”纬度:”></TextBlock>
                <TextBox x:Name=”tbLatitude”
Width=”110″></TextBox>
                <Button x:Name=”btnQueryReverse” Content=”反向搜索”
Click=”btnQueryReverse_Click” Width=”60″
Height=”30″></Button>
            </StackPanel>
        </StackPanel>
    </Grid>

</UserControl>

 

亚洲必赢app在哪下载,3.后台

 public partial class GeocodeServiceDemo : UserControl
    {
        const string BingMapID =
“AkGGA_JlwP7XGV8JxIPb8oEWxrInlLMGKpCe7QM4QB5cg4UGNCqUyjqVfC0B2-XC”;
        public GeocodeServiceDemo()
        {
            InitializeComponent();
           
            MapTileLayer tileLayer = new MapTileLayer();
            ChinaTileSource gts = new ChinaTileSource();

            tileLayer.TileSources.Add(gts.GetChinaTileSource());
            myMap.Children.Add(tileLayer);
        }

        /// <summary>
        /// 检索

  ///遵照国家或地名检索
        /// GeocodeRequest用来拍卖正向检索请求
        /// </summary>
        /// <param name=”sender”></param>
        /// <param name=”e”></param>
        private void btnQuery_Click(object sender, RoutedEventArgs e)
        {
            GeocodeServiceClient client = new GeocodeServiceClient();
            client.GeocodeCompleted += new
EventHandler<GeocodeCompletedEventArgs>(OnGeocodeCompleted);

            //创设请求
            GeocodeRequest request = new GeocodeRequest();
            request.Credentials = new Credentials();

            //BingMap ID
            request.Credentials.ApplicationId = BingMapID;

            //检索条件
            request.Query = this.tbName.Text.Trim();

            //进行搜索
            client.GeocodeAsync(request);
        }

        private void OnGeocodeCompleted(object sender,
GeocodeCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                //获取结果
                GeocodeResponse response = e.Result;
                double latitude =
response.Results[0].Locations[0].Latitude;
                double longitude =
response.Results[0].Locations[0].Longitude;

                this.tbLatitude.Text = latitude.ToString();
                this.tbLongitude.Text = longitude.ToString();

                //根据经纬度和级别设置视图,并展现该岗位
                myMap.SetView(new Location(latitude, longitude), 4);
            }
        }

        /// <summary>
        /// 反向寻找

   ///依照经纬度检索
        /// ReverseGeocodeRequest用来拍卖反向寻找请求
        /// </summary>
        /// <param name=”sender”></param>
        /// <param name=”e”></param>
        private void btnQueryReverse_Click(object sender,
RoutedEventArgs e)
        {
            GeocodeServiceClient client = new GeocodeServiceClient();
            client.ReverseGeocodeCompleted += new
EventHandler<ReverseGeocodeCompletedEventArgs>(OnReverseGeocodeCompleted);

            ReverseGeocodeRequest request = new
ReverseGeocodeRequest();
            request.Credentials = new Credentials();
            request.Credentials.ApplicationId = BingMapID;
            request.Location = new
Location(int.Parse(this.tbLongitude.Text),
int.Parse(this.tbLatitude.Text));
            client.ReverseGeocodeAsync(request);
        }

        private void OnReverseGeocodeCompleted(object sender,
ReverseGeocodeCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                if (e.Result.Results.Count > 0)
                {
                    GeocodeResponse response = e.Result;
                    this.tbName.Text =
response.Results[0].DisplayName;

                    double latitude =
response.Results[0].Locations[0].Latitude;
                    double longitude =
response.Results[0].Locations[0].Longitude;
                   
//依照经纬度和级别设置视图,并出示该职位,这点很重庆大学呀。
                    myMap.SetView(new Location(latitude, longitude),
4);
                }
                else
                    MessageBox.Show(“没有寻找到该地点”);
            }
        }
    }

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图
Copyright @ 2010-2019 亚洲必赢app官方下载 版权所有