Google Map widget

Oct 9, 2008 at 12:52 PM
Edited Oct 10, 2008 at 12:31 AM
Has anyone successfully created a Google Maps widget.  I did a cursory attempt at one and it only renders the very bottom portion of the map.  I would appreciate any help anyone can provide.  I am really after the functionality in the pageflakes page, but would settle for a map that at least completely renders in the widget container.

Here is my ASCX code:

<%

@ Control Language="C#" AutoEventWireup="true" CodeFile="KMLMapWidget.ascx.cs" Inherits="Widgets_KMLMapWidget" %>
<asp:Panel ID="KMLMapContainer" runat="server">
    
<script src=http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAUFMfUZPKMqdMWi3pHxiC-BT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQFOl8WGGoqC57LYJvl-o6kZlCk6A type="text/javascript"></script>
    
<div id="theMapDIV"></div>
</
asp:Panel>

 


Within my code behind's Page Load:

if

(this._Host.IsFirstLoad)
{
    
ScriptManager.RegisterStartupScript(this
                                                                     
typeof(Widgets_KMLMapWidget),
                                                                     
"LoadKMLMap",
                                                                     
"var map; map = new GMap2(document.getElementById('theMapDIV'), G_NORMAL_MAP, 300, 300); map.setCenter(new GLatLng(37.4419, -122.1419), 13);",
                                                                     
true);
}

 

As mentioned above, using this code it will render the Google Maps control within the widget, but it only shows the very bottom of the control.

Karl
Jan 22, 2009 at 6:42 AM
Hi futureshock2038,

Yes i've done .

First of all get the implementation of Shabdar Ghata on codeproject http://www.codeproject.com/KB/custom-controls/Google-Maps-User-Control.aspx

1) put cGoogleMap.cs and GService in App_Code
2) put GoogleMapAPIWrapper.js in widgets directory
3) add two properties in UserProfile.cs in App_code : 

[

SettingsAllowAnonymousAttribute(true)]public virtual GoogleObject GoogleMapObject{get{return ((GoogleObject)(this.GetPropertyValue("GoogleMapObject")));}set{this.SetPropertyValue("GoogleMapObject", value);}}

 

[

SettingsAllowAnonymousAttribute(true)]public virtual GoogleObject GoogleMapObject_Old{get{return ((GoogleObject)(this.GetPropertyValue("GoogleMapObject_Old")));}set{this.SetPropertyValue("GoogleMapObject_Old", value);}}

 

3) modify the Web.Config as specified in Omar's Book to reference this Userprofile
4) transform the google ascx in google widget in widgets directory (get rid of updatepanel)

<%

@ Control Language="C#" AutoEventWireup="true" CodeFile="GoogleMapWidget.ascx.cs" Inherits="Widgets_GoogleMapWidget" EnableViewState="false" %>

 

<%

@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"Namespace="System.Web.UI" TagPrefix="asp" %>

 

 

 

<div id="GoogleMap_Div_Container">

 

<

 

div id="GoogleMap_Div" style="width:<%=GoogleMapObject.Width %>;height:<%=GoogleMapObject.Height %>;">

 

<

 

script src="http://maps.google.com/maps?file=api&amp;v=<%=GoogleMapObject.APIVersion %>&amp;key=<%=GoogleMapObject.APIKey %>" type="text/javascript"></script>

 

<

 

script type="text/javascript" src="GoogleMapAPIWrapper.js">

 

</

 

script></div></div>

5) in google ascx.cs widget replace call to HttpContext.Current.Session by UserProfile.GoogleMapObject

6) in Gservice.cs replace call to HttpContext.Current.Session  by replace call to HttpContext.Current.Profile["GooglemapObject"]

 

Jan 27, 2009 at 2:55 AM
Thanks alot, I will definitely give this a try.

Karl
Oct 14, 2009 at 6:14 AM

anyone got this to work on the latest build?