This site uses cookies to deliver our services. By using this site, you acknowledge that you have read and understand our Cookie and Privacy policy. Your use of Kontext website is subject to this policy. Allow Cookies and Dismiss

Using Bing Maps SOAP Services API in Windows Phone Applications

1203 views 0 comments last modified about 7 years ago Raymond Tang Fahao

In this page

In my previous article, I demonstrated how to use Bing Maps Control in Windows Phone applications; in this article, I will show several other demos about Bing Maps SOAP Services. Please refer to this link for more details about Bing Maps SOAP Services API.

Bing Maps SOAP Services

There are four kinds of services provided by Bing Maps SOAP Services:

I will demonstrate all of these services in the following walkthrough. The project will be based on the previous project I used in Using Bing Maps Control in Windows Phone Applications.

Geocode Service

Geocode service allows you to match an address or place to a map location/geo coordinate (geocoding) or return geographic entities or addresses found at a given location (reverse geocoding).  The URI of this service is http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc. This service contains two main methods: Geocode and ReverseGeocode.

Let’s first service reference to it in Visual Studio: Project BingMapsExample –> Right Click –> Add Service Reference –> Change Namespace as BingMapsGeocodeService.

Bing Maps SOAP Services in Windows Phone Screenshot - 1

Add the below codes to invoke this service:

     private void MapMainLoaded(object sender, RoutedEventArgs e)
        {
            GeocodeServiceTest();
        }

        private void GeocodeServiceTest()
        {
            var geocodeRequest = new GeocodeRequest
             {
                 Options = new GeocodeOptions
                 {
                     Filters = new ObservableCollection<FilterBase>{
                        new ConfidenceFilter {MinimumConfidence = Confidence.High}
                                                                     }
                 }
             };
            //initialize client
            var serviceClient = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            geocodeRequest.Query = "1 Microsoft Way, Redmond, WA";
            serviceClient.GeocodeCompleted +=
                (o, args) =>
                {
                    //if no error, display all the results in the map
                    if (args.Error != null) return;
                    var response = args.Result;
                    var results = from result in response.Results
                                  select new Pushpin
                                             {
                                                 Content = result.DisplayName,
                                                 Background = (Brush)Application.Current.Resources["PhoneAccentBrush"],
                                                 Location = result.Locations[0]
                                             };
                    var coordinates = new LocationCollection();
                    foreach (var pushpin in results)
                    {
                        mapMain.Children.Add(pushpin);
                        coordinates.Add(pushpin.Location);
                    }
                    if (coordinates.Count > 1)
                    {
                        mapMain.SetView(LocationRect.CreateLocationRect(coordinates));
                    }
                    else if (coordinates.Count ==1)
                    {
                        mapMain.Center = coordinates[0];
                        mapMain.ZoomLevel = 17;
                    }
                };

            //Set map control's credentials to this request and begin to request
            mapMain.CredentialsProvider.GetCredentials(credentials =>
            {
                geocodeRequest.Credentials = credentials;
                serviceClient.GeocodeAsync(geocodeRequest);
            });
        }

Below is the screenshot for the query of "1 Microsoft Way, Redmond, WA" and “651 North 34th St # 101, Seattle, WA” :

Bing Maps SOAP Services in Windows Phone Screenshot - 2Bing Maps SOAP Services in Windows Phone Screenshot - 3

Imaginary Service

Imaginary service allows you to retrieve map imaginary information including map URI; with these info, you can display them in your own controls. There are two main methods : GetImageryMetadata and GetMapUri.The URI of this service is http://dev.virtualearth.net/webservices/v1/imageryservice/imageryservice.svc.

As the above case, we will add service reference first with namespace BingMapsImaginaryService.

Below are the sample code to invoke this service and return the URI of the map image of Microsoft Way:

private void ImaginaryServiceTest()
        {
            var location = new Location { Latitude = 47.6396, Longitude = -122.1306 };
            var request = new MapUriRequest
            {
                Options = new MapUriOptions
                {
                    ImageType = ImageType.Png,
                    Style = MapStyle.Aerial,
                    ImageSize =
                        new BingMapsImaginaryService.SizeOfint { Width = 450, Height = 600 },
                },
                Pushpins = new ObservableCollection<Pushpin> { new Pushpin { Location = location} },
                Center = location
            };

            var client = new ImageryServiceClient("BasicHttpBinding_IImageryService");
            client.GetMapUriCompleted +=
                (o, args) =>
                {
                    if (args.Error != null) return;
                    var image = new Image
                                    {
                                        Source =
                                            (ImageSource)
                                            new ImageSourceConverter().ConvertFromString(args.Result.Uri)
                                    };
                    mapMain.Children.Add(image);
                };
            mapMain.CredentialsProvider.GetCredentials(credential =>
            {
                request.Credentials = credential;
                client.GetMapUriAsync(request);
            });
        }

Below is the screenshot of the result:

Bing Maps SOAP Services in Windows Phone Screenshot - 4

Route Service

Route service allows you to calculate route directions to and from multiple locations on a map. The URI of this service is http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc. It contains two methods CalculateRoute and CalculateRoutesFromMajorRoads.

As we did just now, add service reference with namespace BingMapsRouteService.

In the below sample, I will demonstrate how to use this service to draw a poly line from "1 Microsoft Way, Redmond, WA"(47.6381818, -122.1314904) to “651 North 34th St # 101, Seattle, WA” (47.6486964, -122.3503014).

private void RouteServiceTest()
        {
            var request = new RouteRequest
            {
                Options = new RouteOptions { RoutePathType = RoutePathType.Points },
                ExecutionOptions = new ExecutionOptions{ SuppressFaults = true}
            };
            var microsoft = new Location { Latitude = 47.6381818, Longitude = -122.1314904 };
            var google = new Location { Latitude = 47.6486964, Longitude = -122.3503014 };
            request.Waypoints = new ObservableCollection<Waypoint>
                                  {new Waypoint{ Location = microsoft},
                                   new Waypoint {Location = google}
                                  };
            var client = new RouteServiceClient("BasicHttpBinding_IRouteService");
            client.CalculateRouteCompleted +=
                (o, args) =>
                {
                    if (args.Error == null)
                    {
                        var line = new MapPolyline
                        {
                            Locations = new LocationCollection(),
                            Stroke = (Brush)Application.Current.Resources["PhoneAccentBrush"],
                            StrokeThickness = 4

                        };
                        foreach (var point in args.Result.Result.RoutePath.Points)
                        {
                            line.Locations.Add(point);
                        }
                        mapMain.Children.Add(line);
                        mapMain.SetView(LocationRect.CreateLocationRect(line.Locations));
                        //mapMain.ZoomLevel = 2;
                    }
                };
            var pushpinMicrosft = new Microsoft.Phone.Controls.Maps.Pushpin
            {
                Content = "Microsoft",
                Location = microsoft,
                Background = (Brush)Application.Current.Resources["PhoneAccentBrush"]
            };
            var pushpinGoogle = new Microsoft.Phone.Controls.Maps.Pushpin
            {
                Content = "Google",
                Location = google,
                Background = (Brush)Application.Current.Resources["PhoneAccentBrush"]
            };
            mapMain.Children.Add(pushpinMicrosft);
            mapMain.Children.Add(pushpinGoogle);
            mapMain.CredentialsProvider.GetCredentials(credentials =>
                                                           {
                                                               request.Credentials = credentials;
                                                               client.CalculateRouteAsync(request);
                                                           });
        }

Below is the screenshot of Route Service:

Bing Maps SOAP Services in Windows Phone Screenshot - 5

Search Service

Search service allows you to parse a search query as well as return search results. It has only one method: Search. The Uri is http://dev.virtualearth.net/webservices/v1/searchservice/searchservice.svc.

As the way to use this service is the same as the previous samples in this article, I won’t demonstrate any sample. We can use this service to search the restaurants, cinemas, shopping malls around a location.  You can refer to http://msdn.microsoft.com/en-us/library/cc980960.aspx.

Related pages

Surface RT/Pro 版本Windows 8 QQ下载与安装

2512 views   0 comments last modified about 5 years ago

Surface的用户可能会遇到一个难题,在应用商城里边无法搜索到QQ应用程序。但是让我疑惑的是,我的Windows 8.1 系统之前是成功安装了QQ。

后来在腾讯QQ下载官网发现,其实是有QQ应用安装的链接:

按照如下方法安装Surface QQ.

Have fun!

image

View detail

my first begining with Windows 7

101 views   0 comments last modified about 9 years ago

Maybe it is a little late now due to busy work,anyhow,it is better to do lately than never to do.

View detail

[教程]在Windows Phone 程序中使用LINQ to XML以及执行数据绑定

260 views   0 comments last modified about 7 years ago


LINQ是Language Integrated Query的简写,中文名称是语言集成查询,它是一组技术的组合,包括LINQ to DataSet(typed 以及untyped),LINQ to SQL(适用于SQL Server数据库),LINQ to XML(包括内存中以及XML文件中的数据),LINQ to Object,LINQ to Entities(结合Entity Framework使用)等。这些技术建立在将查询功能直接集成到 C# 语言(以及 Visual Basic 和可能的任何其他 .NET 语言)的基础上。借助于 LINQ,查询现在已是高级语言构造,就如同类、方法、事件等等。具体参考MSDN文档介绍View detail

SVN 中文子目录权限失效的解决方案

239 views   0 comments last modified about 9 years ago

svn对于非英文文件名和目录名使用utf-8格式编码处理,要对中文目录进行正确控制,
对于authz文件应该使用无BOM的utf-8格式,如何将默认的文件转为utf-8?可以使用UltraEdit编辑器存储的时候把格式选择“UTF-8 无BOM”;

View detail

LINQ to SQL in Windows Phone 7 Error: An overflow occurred while converting to datetime.

453 views   0 comments last modified about 7 years ago

Resolve the issue in Linq to SQL in Windows Phone 7 App:
An overflow occurred while converting to datetime.

View detail

Add comment

Please login first to add comments.  Log in New user?  Register

Comments (0)

No comments yet.