This tutorial will illustrate how you can use the Google Maps API in your ASP.NET projects using C#.
Google maps is a wonderful tool that provides great functionality when it comes to world maps. You can use them to compute distances between cities, get driving directions, walking directions, locations of your favorite business establishments, and much more.
Getting Information from the Google Maps API
The objective of using this API is to get relevant data stored in Google maps and use that data in your ASP.NET web application. The first step in this process is for your web application to request data from the Google maps API. The request comes in the form of a GET request URL. The request URL contains parameters that depend on what information you need. You will learn how to craft a request URL in this tutorial.
After receiving your request, the Google Maps API server will examine your request and return some results. You will then retrieve this information using your C# scripts. The data format that you will receive is JSON (http://www.json.org/) and still needs some processing to retrieve specific information. This processing includes decoding the JSON data and finally outputting the results to the browser.
Example: Compute Driving Distance between Major Cities
It is hard to understand this concept without a working example. Suppose you would like to create an ASP.NET web application that will accept two inputs from the user. These inputs are the name of two major cities that are known by Google maps. The objective of this application is to compute the driving distances between these cities. Let’s use Google Maps API to accomplish this objective:
1.) Create the website project in Visual Web Developer (VWD) Express. Go to File – New Web Site.
2.) Under “Visual Studio Installed Templates”, click “ASP.NET Web Site”.
3.) Make sure that the following is set:
Location: File System
Language: C#
Path: Windows path to your project, for example: L:aspdotnetprojectsexample_google_maps
4.) Finally, click OK.
Let’s create the web form that will let the user enter input:
a.) Click and drag two text box web controls for entering inputs.
b.) Click and drag one button controls for submitting the form.
c.) Click and drag one label control between the button controls for displaying the distance results.