Learn WPF Using Google Place API8 min read

Introduction

In this article, we will learn WPF using Google Place API with the WPF control web browser in Visual Studio 2015.

In this article, we are going to:

  • Create a WPF Application.
  • Using Google Place API.
  • Configure the API.

Create a WPF Application

Open Visual Studio 2015

WPF

Select the File menu >New > Click Project.
WPF

Select Windows templates, and choose the WPF Application. Then click “ok “after filling in the name and location.

After you complete the solution explorer, it will load basic bundles.
WPF

Open the ManiWindow.xaml file and Change it from <Grid> to <DockPanel>. It will load based on resolution.
WPF

Then drag a web browser from the Toolbox to the Designer window.

Adding some extra controls to get a result.

Using Google Place API

If you’re going to use Google API, you must sign up for a Gmail account. Once you successfully login click here. In this site, you have to click the “GET a Key” button to flow through a process where you will:

  • Create or select a project.
  • Enable the API.
  • Get an API Key.

Create and Enable the API

Create a project name and click the “CREATE AND ENABLE API.”
WPF

Get an API Key

In this process, you are getting keys ready to use in your application, so copy the key and click the “FINISH” Button.
WPF

Configure the API

I have checked this key using the URL below, and found out what the actual result is.

https://maps.googleapis.com/maps/api/distancematrix/xml?units=imperial&origins=Washington,DC&destinations=New+York+City,NY&key=YOUR_API_KEY
WPF

I have configured the URI and Key in APP.CONFIG.

Code Behind

First, I have initiated the URL for a web browser.

Create the new class for retrieving and storing the values.

Output 1

WPF

Then I get data from App.config.

Here, I have used the web URL to look for the UI and API URL and used it to get the values of this search’s result. Once you click the “Calculate” button, follow the below code.

I have added the distance mode in the API URL, as follows:

“&mode=driving&sensor=false&language=en-EN&units=imperial&Key=”

But, per our users’ needs, we can get the result from Google Place API.

After the calculation, I will navigate the Web URL to the web browser.

Run the application or Click (F5)

Output 2

WPF

Conclusion

In this article, we have learned WPF, using the Google Place API. If you have any queries, please tell me through the comments section. Your comments are very valuable.

Happy Coding!

Author Profile

Thiruppathi Rengasamy
I 'm a .Net Developer & Blogger. And also I'm working as senior software engineer in Microsoft Technologies for 5+ Years.I would like to spend my precious time in writing articles, research in .Net technologies and to learn new technologies.