Front-end:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "mapsdemo. aspx. cs" inherits = "_ default" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "head1" runat = "server">
<Title> my 51 maps </title>
<SCRIPT type = "text/JavaScript" src = "http://api.51ditu.com/js/maps.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "http://api.51ditu.com/js/ezmarker.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
Function onload ()
{
VaR coordinates = Document. getelementbyid ("hidaddress"). value. Split (",");
VaR maps = new ltmaps ("mapdiv ");
VaR point = new ltpoint (coordinates [0], coordinates [1]);
Maps. centerandzoom (New ltpoint (coordinates [0], coordinates [1]), coordinates [2]);
Var control = new ltstandmapcontrol ();
Maps. addcontrol (control );
VaR marker = new ltmarker (point );
Maps. addoverlay (Marker );
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Input id = "hidaddress" runat = "server" type = "hidden"/>
* Tip: use it on a map
The approximate position is marked. The result may be inaccurate and is for reference only.
<SCRIPT type = "text/JavaScript">
Function setmap (point, zoom)
{
Document. getelementbyid ("longpolling"). value = point. getlongpolling ();
Document. getelementbyid ("latitude"). value = point. getlatitude ();
Document. getelementbyid ("level"). value = zoom;
Document. form1.submit ();
}
VaR EZ = new ltezmarker ("ezmarker ");
VaR coordinates = Document. getelementbyid ("hidaddress"). value. Split (",");
VaR point = new ltpoint (coordinates [0], coordinates [1]);
EZ. setvalue (point, parseint (coordinates [2]);
Ltevent. addlistener (EZ, "Mark", setmap );
</SCRIPT>
<Input runat = "server" type = "hidden" id = "longpolling" name = "longpolling"/>
<Input runat = "server" type = "hidden" id = "latitude" name = "latitude"/>
<Input runat = "server" type = "hidden" id = "level" name = "level"/>
<Br/>
<Div id = "mapdiv" style = "width: 600px; Height: 400px;">
</Div>
<SCRIPT type = "text/JavaScript">
Onload ();
</SCRIPT>
</Form>
</Body>
</Html>
Background:
Using system;
Using system. configuration;
Using system. Data;
Using system. LINQ;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. xml. LINQ;
Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
String address = NULL;
If (! Ispostback)
{
Address = "12085627,3201350, 3"; // read database coordinates
This. hidaddress. value = address;
}
Else
{
String addressupdate = This. longpolling. Value + "," + this. Latitude. Value + "," + this. level. value;
Address = addressupdate; // update database coordinates
This. hidaddress. value = address;
}
}
}