Help us translate this website and improve this translation and earn free licenses!
Anonymous user  |  Log in  |  Create Account

How to...

GDirections Advanced

If we do not want to autogenerate GDirection, and we want to design a more personal interface, set "autoGenerate" to false.

GMaps still continues to do almost all our work. All we have to do is set the boxes for start and end points, the submit button, and "div" where the directions will go.

In addition, define "locale" to indicate Language-Culture where we are working.

Define the following properties for correct operation:
  • buttonElementId: The button ID. Input must be "< type=button/>" NOT "< asp:Button/>". 
  • fromElementId: The textbox that corresponds to the starting point.
  • toElementId: The textbox that corresponds to the ending point.
  • divElementId: The div ID where the directions will go.
  • locale: string that defines the culture. For example "Es-ES", "in-GB", "fr-CA", etc.
  • travelMode: The mode of travel, such as driving (default) or walking.
  • avoidHighways: If true directions will attempt to exclude highways when computing directions. Note that directions may still include highways if there are no viable alternatives.
  • preserveViewport: By default, when a Directions object has a map, the map is centered and zoomed to the bounding box of the the directions result. When this option is set to true, the viewport is left alone for this request (unless it was never set in the first place).

Start Location: End Location:


Code.aspx
Start Location: <asp:TextBox ID="tb_fromPoint" runat="server"></asp:TextBox>
End Location: <asp:TextBox ID="tb_endPoint" runat="server"></asp:TextBox>
<input type="button" id="bt_Go" value="Come on!" />

<cc1:GMap ID="GMap1" runat="server" />
<div id="div1"></div>
Code.aspx.cs
protected void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack)
{
GDirection direction = new GDirection();
direction.autoGenerate = false;
direction.buttonElementId = "bt_Go";
direction.fromElementId = tb_fromPoint.ClientID;
direction.toElementId = tb_endPoint.ClientID;
direction.divElementId = "div_directions"; direction.clearMap = true;


// Optional
// direction.locale = "es-ES";

GMap1.Add(direction);
}
}
Powered by Subgurim.NET