Get Address by Location in Bing Map in Windows Store App (XAML)


Introduction

In my previous article on custom pushpin, we had seen how to add a pushpin when tapped/clicked on a point in Bing Map. In this article the concept is almost same, except that we would fetch the Address or name of that point and display it in the pushpin.

Sound great right!

Let’s proceed.

In case you have missed the previous articles here are they:

1. Bing Map for Windows Store Apps

2. Starting Bing Map for Windows Store App (XAML)

3. Enabling Location Capability with Bing Map in Windows Store App (XAML)

4. Custom Pushpin in Bing Map for Windows Store App (XAML)

Creating Custom Pushpin

To create a custom pushpin, we need add a user control and design it. We have already seen achieving this in my last post. I have just revamped the design to contain more elements in the area.

Plus added properties to bind the address.

Adding Pushpin to Bing Map

To add the pushpin, you need to follow. Remember that this method allows us to access a single instance of pushpin to access for updating the info. To add multiple pushpins; we would see in another post.

We have subscribed to the Tapped event of the Bing Map, so that when user clicks/taps the event would be fired and we can update the pushpin.

What we are doing above is taking the location from the pixel the user had tapped/clicked. Then we are changing the location of the pushpin and making it center, which is achieved using SetView method.

Now the GetAddressByLocation method helps us to find the name/address of the point by making a GET request to Bing Map’s REST API.

Also note that in this sample we are using the output as JSON, which you can also change it to XML if required.

For XmlDeSerializer, you can follow Kunal’s nice post as follows:

#Win8Dev Tutorial: Serializing Objects in your WinRT Applications using XmlDeSerializer

The following is the helper method to de-serialize the response from the API.

This should be working, let’s see.

Run the application and you should see your point’s name/address.

Hope this article helps, thanks for reading.

Download Source code: Click Here

In case you have missed the previous articles here are they:

1. Bing Map for Windows Store Apps

2. Starting Bing Map for Windows Store App (XAML)

3. Enabling Location Capability with Bing Map in Windows Store App (XAML)

4. Custom Pushpin in Bing Map for Windows Store App (XAML)

Advertisements