How can i bind marker Latitude and Longitude to datasource fields

Nov 9, 2012 at 10:47 AM

Thank you for this useful control. I'm trying to find out the simplest way to assign values from datasource fields obtained from the underlying sql data reader to the Marker's latitude, longitude and info attributes.

This example shows how to assign values directly     

<artem:GoogleMap ID="GoogleMap1" runat="server" Latitude="42.1229" Longitude="24.7879" Zoom="12" EnableScrollWheelZoom="true" CssClass="map">
        </artem:GoogleMap>
        <artem:GoogleMarkers ID="GoogleMarkers1" TargetControlID="GoogleMap1" runat="server">
            <Markers>
                <artem:Marker Position-Latitude="42.132" Position-Longitude="24.75" Title="Click on the marker"
                    Info="Text of marker 1">
                </artem:Marker>
               </Markers>
            <MarkerOptions Draggable="true">
            </MarkerOptions>
        </artem:GoogleMarkers>

By adding inline expressions almost makes it work, but the same expressions don't work with the GoogleMarker tag:

<artem:GoogleMap ID="GoogleMap1" runat="server" Latitude='<%# Eval("decLatitude")%>' Longitude='<%# Eval("decLongitude") %>' Zoom="12" EnableScrollWheelZoom="true" CssClass="map">
</artem:GoogleMap>
<artem:GoogleMarkers ID="GoogleMarkers1" TargetControlID="GoogleMap1" runat="server">
<Markers>
<artem:Marker Position-Latitude='<% Eval("decLatitude")%>' Position-Longitude='<%# Eval("decLongitude")%>' Title="Click on the marker"
Info="value read from the datasource">
</artem:Marker>
</Markers>
<MarkerOptions Draggable="true">
</MarkerOptions>
</artem:GoogleMarkers>

  

I have considered accessing the GoogleMarker from code behind and setting the lat and long values in code such as below and it almost works but there are clitches

 protected void Page_Load(object  sender, EventArgs e)

{

// varLat, varLong and varInfo read from page interface using FindControl method

Marker mrk = new Marker();

LatLng pos = new LatLng(varLat, varLong);

mrk.Position = pos;

mrk.Info = varInfo;

mrk.Draggable = true;

GoogleMap1.Markers.Add(mrk);

}

The problem i experience here is how to attach the Drag event to the marker. I want to reetriev the marker's new lat lng whenever its dragged.

Any ideas?