Click here to Skip to main content
11,720,545 members (70,730 online)
Click here to Skip to main content

Google Map WebPart

, 23 Apr 2008 CPOL 39.5K 940 38
Rate this:
Please Sign up or sign in to vote.
A Google map WebPart.

Introduction

This article presents a Google map WebPart.

Using the code

The rendering on the Google map control is performed in the WebPart Render event. The Google map control is initialized using the ClientScriptManager object.

protected override void Render(HtmlTextWriter writer)
{
    string rScript = "";
    rScript += &quot;<script src=\&quot;http://maps.google.com/maps?file=api&amp;v=2&amp;key=&quot; + 
               m_rGoogleKey + &quot;\&quot;\n type=\&quot;text/javascript\&quot;></script>

In order to be able to modify the Google map properties, I created an EditorPart class, allowing the user to change the Google API key or the dimensions of the WebPart.

public class GoogleMapEditor : System.Web.UI.WebControls.WebParts.EditorPart
{
    TextBox googleKey = new TextBox();
    TextBox tbWidth = new TextBox();
    TextBox tbHeight = new TextBox();
    TextBox tbLat = new TextBox();
    TextBox tbLong = new TextBox();
    TextBox tbZoom = new TextBox();
    CheckBox chkDisplayZoom = new CheckBox();
    CheckBox chkDragging = new CheckBox();
    CheckBox chkIcon = new CheckBox(); 

Just like a standard WebPart, editor parts must override the CreateChildControls to build a user interface. The user interface is drawn by overriding the RenderContents method.

protected override void RenderContents(HtmlTextWriter writer)
{
    writer.Write(&quot;Google Key <br/>&quot;);
    googleKey.RenderControl(writer);
    
    writer.Write(&quot;<br/>Width<br/>&quot;);
    tbWidth.RenderControl(writer);
    
    writer.Write(&quot;<br/>Height<br/>&quot;);
    tbHeight.RenderControl(writer);

2.jpg

Figure 1. Custom Editor

Result

1.jpg

Figure 2. Google Map WebPart

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Simon Bonello
Architect
Malta Malta
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralLocation change when I set regional settings to a different region Pin
Anthonyyy21-Jun-10 5:36
memberAnthonyyy21-Jun-10 5:36 
GeneralGoogle Map Nigeria [modified] Pin
mbaocha3-May-09 21:43
membermbaocha3-May-09 21:43 
QuestionHow I can pass paramater of langitude/latitude paramaeter from my sharepoint list Pin
sonashish29-Jun-08 9:16
membersonashish29-Jun-08 9:16 
AnswerRe: How I can pass paramater of langitude/latitude paramaeter from my sharepoint list Pin
surajsukumar6-Nov-08 0:09
membersurajsukumar6-Nov-08 0:09 
GeneralRe: How I can pass paramater of langitude/latitude paramaeter from my sharepoint list Pin
MadWhiteHatter16-Mar-09 8:56
memberMadWhiteHatter16-Mar-09 8:56 
GeneralRe: How I can pass paramater of langitude/latitude paramaeter from my sharepoint list Pin
mrajpurkar16-Jul-09 3:36
membermrajpurkar16-Jul-09 3:36 
GeneralRe: How I can pass paramater of langitude/latitude paramaeter from my sharepoint list [modified] Pin
wankakoch21-Oct-09 4:32
memberwankakoch21-Oct-09 4:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150901.1 | Last Updated 23 Apr 2008
Article Copyright 2008 by Simon Bonello
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid