This project is read-only.

GoogleMarkers binding with XmlDataSource ?

Dec 4, 2012 at 9:31 AM
Edited Dec 4, 2012 at 9:35 AM

Hi, is there any way to bind GoogleMarkers with XmlDataSource (latitude, longitude, etc) ?

<asp:XmlDataSource ID="xds_GetStop" XPath="BusDynInfo/BusInfo/Stop" runat="server"></asp:XmlDataSource>
<artem:GoogleMap ID="gmap_GoRoute" runat="server"
    Key='<%$appSettings:Google_Maps_Key%>'
    Latitude="24.136753"
    Longitude="120.685114">
</artem:GoogleMap>
<artem:GoogleMarkers ID="gmarker_GoRoute" runat="server"
    DataLatitudeField="latitude"
    DataLongitudeField="longitude"
    TargetControlID="gmap_GoRoute">
</artem:GoogleMarkers>
protected void ddl_Route_SelectedIndexChanged( object sender, EventArgs e ) {
    if ( ddl_Route.SelectedValue == "-1" ) {
        // Still do nothing here because user hasnt choose a route
    } else {
        // http://citybus.taichung.gov.tw/xmlbus2/StaticData/GetStop.xml?routeIds=85
        xds_GetStop.DataFile = String.Format( "http://citybus.taichung.gov.tw/xmlbus2/StaticData/GetStop.xml?routeIds={0}", ddl_Route.SelectedValue );
        ddl_Stop.DataSource = xds_GetStop;
        gmarker_GoRoute.DataSource = xds_GetStop;
    }
    ddl_Stop.DataBind();
    gmarker_GoRoute.DataBind();
}
[InvalidCastException: 指定的轉換無效。]
   Artem.Google.UI.GoogleMarkers.PerformDataBinding(IEnumerable data) +736
   Artem.Google.UI.GoogleMarkers.<PerformSelect>b__26(IEnumerable data) +100
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33
   Artem.Google.UI.GoogleMarkers.PerformSelect() +161
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
   NFU.IM.BUS.modules.QueryTime.ddl_Route_SelectedIndexChanged(Object sender, EventArgs e) +152
   System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e) +116
   System.Web.UI.WebControls.DropDownList.RaisePostDataChangedEvent() +133
   System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +13
   System.Web.UI.Page.RaiseChangedEvents() +132
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1644
Dec 4, 2012 at 10:16 AM

ok,

i noticed that latitude and longitude in my xml source is 24.1105166666667 and 120.619005.

<Stop Id="116" routeId="85" nameZh="高鐵臺中站" seqNo="1" pgp="0" terminal="0" districtId="1" GoBack="1" latitude="24.1105166666667" longitude="120.619005"/>
<Stop Id="11177" routeId="85" nameZh="光日站" seqNo="2" pgp="0" terminal="0" districtId="1" GoBack="1" latitude="24.1085959992" longitude="120.626063347"/>
<Stop Id="115" routeId="85" nameZh="大慶火車站" seqNo="3" pgp="0" terminal="0" districtId="1" GoBack="1" latitude="24.1191283333333" longitude="120.647835"/>
<Stop Id="114" routeId="85" nameZh="中山醫學大學" seqNo="4" pgp="0" terminal="0" districtId="1" GoBack="1" latitude="24.12248" longitude="120.648876666667"/>
<Stop Id="113" routeId="85" nameZh="文心三民西路口" seqNo="5" pgp="0" terminal="0" districtId="1" GoBack="1" latitude="24.1264716666667" longitude="120.646473333333"/>

the values cause the cast exception occur.

here is the modified code in the line 972 and 973 below,

GoogleMarkers.css

foreach (object dataItem in data) {
    marker = new Marker();

    //if (hasAddressDataField)
    //    marker.Address = DataBinder.Eval(dataItem, DataAddressField, "");
    if (hasIconDataField)
        marker.Icon = DataBinder.Eval(dataItem, DataIconField, null);
    if (hasInfoDataField)
        marker.Info = DataBinder.Eval(dataItem, DataInfoField, null);
    if (hasLatitudeDataField)
        //marker.Position.Latitude = (double)DataBinder.Eval(dataItem, DataLatitudeField);
        marker.Position.Latitude = Convert.ToDouble( DataBinder.Eval( dataItem, DataLatitudeField ) );
    if (hasLongitudeDataField)
        //marker.Position.Longitude = (double)DataBinder.Eval(dataItem, DataLongitudeField);
        marker.Position.Longitude = Convert.ToDouble( DataBinder.Eval( dataItem, DataLongitudeField ) );

    this.Markers.Add(marker);
}
wish this can help :)