How to Use Google Maps in C#
C# is an interpretive programming language developed by the Microsoft Corporation for use in the .NET development environment. By creating a C# user control, a program developer can use the Google Map programming interface in dynamically generated web pages developed in the .NET programing environment. You will need to adhere to some basic web page formatting requirements by Google as well as request a developer key in order to deploy web pages that you create using C# and the Google Maps Application Programming Interface (API).
Instructions
-
-
1
Open your .NET Integrated Development Environment (IDE) program by double-clicking on the program icon located on your computer's desktop.
-
2
Open a new ASP project and edit the HTML namespace for the file to include the following DOCTYPE declaration:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
The Google Maps API requires the strict version of the W3 schema, which is not normally used across the web. -
-
3
Enter the Microsoft schema definition after the DTD declaration to ensure the webpage will be compatible with the .NET environment:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:v="urn:schemas-microsoft-com:vml"> -
4
Enter the following style declaration in the "Head" section of the HTML page in order to define the correct interpretive behavior for the C# and Google Maps programming code:
<style type="text/css">
v\:*
{
behavior:url(#default#VML);
}
</style> -
5
Enter the following form information in the body section of the web page to create a Google Map that displays in the center of the webpage with a height of 300 pixels and width of 500 pixels.
<form id="Form1" method="post" runat="server">
<wcp:GMap runat="server" id="gMap" Width="500px" Height="300px" />
</form> -
6
Create a C# programming function that will load when the web page is viewed as well as enable and center the Google Map display on the web browser with the following programming code:
protected GMap gMap;
private void Page_Load(object sender, System.EventArgs e)
{
gMap.CenterAndZoom(new GPoint(-122.141944F, 37.441944F), 4);
} -
7
Select the "Save" and "View Project in Web Browser" menu options to view the Google Map display enabled by C# in your ASP web page.
-
1