This project is read-only.

Get lat/long from serverside

Apr 11, 2008 at 2:46 PM
Hi!

GoogleMap is realy a neat control, when showing maps on web. I just have one problem.

I have the GoogleMap control in a updatepanel that is triggerd by a timer.
And in the server side time.tick handler function I update the markers on the map.
But it seems when doing this the mapobject don’t remember the location and the
lat/long must be set again, for the map to show.
How can I get this values(lat/long) in serverside code? The user can have dragged the map, so can’t use the start values…

Clientside code:

<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="Timer1" runat="server" Interval="6000">
</asp:Timer>
<div>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<artem:GoogleMap ID="GoogleMap1" runat="server" Width="800px" Height="600px" InsideUpdatePanel="True" Key="MyAPIKey…">
</artem:GoogleMap>
 
Apr 14, 2008 at 7:01 AM
I'm working on next release, where that should be fixed.

Regards
Apr 14, 2008 at 7:37 AM
Hi, do you know when the next release will be available..?
Apr 14, 2008 at 9:28 AM
Hi,
In the next couple of days I hope.

Regards
Apr 14, 2008 at 12:34 PM
Edited Apr 14, 2008 at 12:37 PM
I looked at the GoogleMapClientUpdate example. And thought it did the job. But it seem's difficult to add the InfoWindow to a marker from
this approach? Tried just to set the Text attribute, but it will not show in the browser, when clicking on the marker.
Think I need to add a marker listener for the click event. But how is that possible to add in the string that is sendt to RegisterClientScriptBlock?

private void AddMarkers(ref StringBuilder buff)

{
TaxiMap2.DL.DataStore DbStore = new TaxiMap2.DL.DataStore();
DataSet MarkerData = new DataSet();
DbStore.GetMarkerData(ref MarkerData);
String Txt = Convert.ToString('"') + "Test" + Convert.ToString('"');;
double lat, lng;
buff.AppendFormat("{0}.Markers = null;{0}.clearOverlays();", GoogleMap1.ClientMapID);

int i = 0;
for (i = 0; (i <= MarkerData.Tables0.Rows.Count); i++) {
lat = Double.Parse(Convert.ToString(MarkerData.Tables0.Rowsi.ItemArray0) , CultureInfo.InvariantCulture);
lng = Double.Parse(Convert.ToString(MarkerData.Tables0.Rowsi.ItemArray1) , CultureInfo.InvariantCulture);
buff.AppendFormat("{0}.addMarker(", GoogleMap1.ClientMapID).Append(").AppendFormat("Latitude: {0},Longitude:{1},Text:{2}", JsUtil.Encode(lat), JsUtil.Encode(lng), Txt).Append();");
i = (i + 1);
}

buff.AppendFormat("{0}.render();", GoogleMap1.ClientMapID);

}
Apr 15, 2008 at 7:16 AM
Hi,
This was copied to working items.
In the comming release, GoogleMap control will register for change zoom and lat/lng on the client and will record the new values and then send them back to the server.
So, in next release you'll be able just to get them from GoogleMap control properties Zoom, Latirude, Longitude etc.
In that way the GoogleMap control will "remember" the location and zoom during postbacks.

Hope this solves your problem

Regards,
Apr 15, 2008 at 7:17 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Apr 15, 2008 at 1:24 PM
Ok, thank you. That will solve the problem.
Apr 16, 2008 at 11:58 AM
Hi,

Did download the GoogleMap release 3.3 today. But it seems the InsideUpdatePanel property still is there?
and it did not save the lat/long in postback? it should have been possible to get in
map.Latitude and map.Longitude or somwhere else?

Regards
Apr 16, 2008 at 1:13 PM
Edited Apr 16, 2008 at 1:14 PM
Hi,
Yes, I forgot to remove the property InsideUpdatePanel in GoogleMap but it is not used in the render code.
You can see a live working sample of what you need at Postback Persistence Sample .
Just go to the page position map by address, zoom in/out and change map type to sattelite for example.
Click button Submit, which just makes a postback and you should see the changes you have done are persisted after that.
Click Save button to save a location and settings during postback as well.
Go to other location, change zoom and map type, but as far as you click Restore button you will go to the last saved position, zoom amd map type.
Same page is included in the Sample Website which you can download from release files.

Hope this helps
Regards
Apr 17, 2008 at 8:51 AM
Thanks the demo is working nice!

But have still one issue.
If I would like to have a timer on the aspx page, and let that do the postback, not a submitt button. It seems the lat/long is 0.0.
Maybe ajax timer postback is not full postback, but don't know this for sure. Same happens when trying to put a refresh on the page <meta http-equiv="refresh" content="5">, the lat/long/zoom is empty. I don't know why the lat/long is set, on postback, only on pushing buttons? But will try to find a work around.

Regards.
Apr 18, 2008 at 8:52 AM
Did find a usable solution for this issue. So I post the code here. The aspx has timer that get’s the map values (lat/long/zoom) continuously, and put them into form elements.
And then a timer in the updatepanel does a postback. Where in codebehind the values are fetched from the form elements…

In aspx file:

<script language="JavaScript">

var timerID = 0;
var tStart = null;

function MapTimer() {
if(timerID) {
clearTimeout(timerID);
clockID = 0;
}

if(!tStart)
tStart = new Date();

var tDate = new Date();
var tDiff = tDate.getTime() - tStart.getTime();

tDate.setTime(tDiff);

timerID = setTimeout("MapTimer()", 1000);
if (tDate.getSeconds() > '1'){
document.forms'aspnetForm'.elements'ctl00_phContent_funcpoint'.value = ctl00phContentGoogleMap1_Map.getCenter();
document.forms'aspnetForm'.elements'ctl00_phContent_funczoom'.value = ctl00phContentGoogleMap1_Map.getZoom();
tStart = null;
}
}

</script>
</head>

<body onload="MapTimer()">....
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<input type="hidden" runat="server" id="funcpoint">
<input type="hidden" runat="server" id="funczoom">
<asp:Literal ID="_ltrScript" runat="server"></asp:Literal>
<asp:Timer ID="Timer1" runat="server" Interval="30000"></asp:Timer>
<artem:GoogleMap ID="GoogleMap1" EnableViewState="true" runat="server" Width="980px" Height="780px" EnableScrollWheelZoom="true"
BorderStyle="Solid" BorderColor="#999999" EnableDoubleClickZoom="True" BorderWidth="1" ShowMapTypeControl="False"
Key="…">
</artem:GoogleMap>.....

In code behind:

Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Dim MapCenter As String()
Dim MapLat As String = ""
Dim MapLong As String = ""
Dim MapZoom As String = ""

If funcpoint.Value.ToString <> "" And funczoom.Value.ToString <> "" Then
MapCenter = funcpoint.Value.ToString.Split(",")
MapLat = MapCenter(0).Replace("(", "")
MapLong = MapCenter(1).Replace(")", "")
MapZoom = funczoom.Value.ToString.Trim
Else
'Not valid postback values, set standard valus..

End If

GoogleMap1.Latitude = Double.Parse(MapLat.Trim, CultureInfo.InvariantCulture)
GoogleMap1.Longitude = Double.Parse(MapLong.Trim, CultureInfo.InvariantCulture)
GoogleMap1.Zoom = CInt(MapZoom)


AddMarkers()


Sep 20, 2008 at 7:36 AM
Hi ,
I just have no words but its a really nice job, Its seems for me is the only solution that it works inside the update panel, you know has  lost the lat and  lng, there exists another upgrades to fix that?Velio seems to be so busy always, is a nice guy, but it seems to be a busy guy for me that only thing that i work its your solution its work fine.
I did the same sample just replaces for a Hiddenfiels insted of inputs and it works just perfect.
Remember the Sample Clientsideupdate?, this work better
But I have an issue I have a page inherits from amasterpage  and i dont know where put the 

onload

="MapTimer()

and the javascript code

Sep 22, 2008 at 1:09 PM
Hi,

Yes Velio seems to be busy lately.. I did try to work with the  Client Update Sample, but did not manage to make it work for updates.

I have not found any updates that fixes the issue of loosing lat/long on postback's. Tought this was fixed for a long time ago but..


I have placed the:  <body onload="MapTimer()"..  and the javascript in the masterpage....

and put the form elemets:

<

INPUT id="funczoom" type=hidden...
...


In the aspx content page..


-Pelle


Sep 22, 2008 at 7:44 PM
Thank you Pelle
Now its working good
I really apreciate your help
Regards