Ok I have split it into two different controls the first is working and displaying the map.
when I redirect to the other to get the directions, the page goes straight to google .com and shows a search bar.
Here is the code for the first
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GetDrivingDirections.ascx.cs" Inherits="CMSApp.CMSWebParts.RohlWebParts.GetDrivingDirections" %>
<script type="text/javascript">
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var map2;
var gdir;
var geocoder = null;
var addressMarker;
var name;
var addr;
var phone;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(0, 0);
var mapOptions = {
zoom: 12,
center: latlng,
navigationControl: true,
navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL },
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
name = document.getElementById("p_lt_ctl00_DrivingDirections_name").value;
addr = document.getElementById("p_lt_ctl00_DrivingDirections_addr").value;
phone = document.getElementById("p_lt_ctl00_DrivingDirections_phone").value;
var contentstring = createHTMLNode(name + '<br/>Address: ' + addr + '<br/>Phone: ' + phone);
var infowindow = new google.maps.InfoWindow({
content: contentstring
});
geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': addr }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
document.getElementById("p_lt_ctl00_DrivingDirections_addrLatLng").value = results[0].geometry.location;
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
infowindow.open(map, marker);
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(map);
directionsDisplay.setMap(map2);
directionsDisplay.setPanel(document.getElementById('directions'))
document.getElementById("showroomContainer").innerHTML = '<span class="nameSpan">' + name + '</span><br/><span class="addrSpan">Address: ' + addr + '</span>' + '</span><br/><span class="phoneSpan">Phone: ' + phone + '</span>';
//setDirections("San Francisco", addr, "en_US");
}
function calcRoute() {
document.getElementById("directions").innerHTML = "";
document.getElementById("dirHeader").style.display = "";
document.getElementById("dirBody").style.display = "";
document.getElementById("mapBody").style.display = "none";
directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(map2);
directionsDisplay.setPanel(document.getElementById('directions'))
var start = document.getElementById("fromAddress").value;
var end = document.getElementById("p_lt_ctl00_DrivingDirections_addrLatLng").value;;
var request = {
origin: start,
destination: end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
function createHTMLNode(text) {
try {
var n = document.createElement('div');
n.setAttribute('style', 'width:250px; font-weight:bold;text-align:left;padding-top:10px; font-size:10px;')
if (n.style) {
n.style.fontWeight = 'bold';
n.style.textAlign = 'left';
n.style.width = '250px';
n.style.paddingTop = '10px';
n.style.fontSize = '10px';
}
if (text)
n.innerHTML = text;
return n;
}
catch (e) {
}
}
function qparam(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div style="width:100%;">
<form action="#" >
<input type="hidden" id="name" name="name" runat="server"/>
<input type="hidden" id="addr" name="addr" runat="server" />
<input type="hidden" id="addrLatLng" name="addrLatLng" runat="server" />
<input type="hidden" id="phone" name="phone" runat="server" />
<table style="width: 100%;" cellpadding="0" cellspacing="0">
<tbody>
<tr >
<td width="49%"/>
<td nowrap="" width="610" style="color: #ffffff; font-weight: normal; font-size: 20px; text-align: left; padding-top: 5px;">
<a name="Top"/>
<table class="header">
<tr>
<td style="width:480px" id="showroomContainer" class="showroomContainer">
ROHL HOSPITALITY PROJECTS
</td>
<td>
<div class="non-printable">
<input type="button" onclick="window.print(); return false;" value="Print"/>
</div>
</td>
<td>
<div class="non-printable">
<input type="button" onclick="javascript: window.close(); return false;" value="Close"/>
</div>
</td>
</tr>
</table>
</td>
<td width="49%"/>
</tr>
</table>
<div style="width:600px; padding:10px 80px 0 80px;">
<table class="directions">
<tr>
<!--<td valign="top"><div id="emptyDiv" style="width: 275px;"> </div></td>-->
<td valign="top" align="left" style="font-family:'Times New Roman', Times, serif; font-size:16px; color:#802719; font-weight:bold;" colspan="2"><div id="fromContainer" class="non-printable" style="width: 100%;">Please enter your starting address for custom driving directions: </div></td>
</tr>
<tr>
<td>
<input class="non-printable" type="text" id="fromAddress" size="25" style="width:522px;" runat="server"/>
</td>
<td>
<asp:Button ID="btnSubmit" runat="server" class="submit non-printable" OnClick="btnSubmit_Click" Text="Submit" />
</td>
</tr>
</table>
</form>
<br/>
<table class="directions">
<tr id="dirHeader" style="display:none;"><th>Directions</th><th>Map</th></tr>
<tr id="dirBody" style="display:none;">
<td valign="top"><div id="directions" style="width: 275px"></div></td>
<td valign="top"><div id="map_canvas" style="width: 310px; height: 400px"></div></td>
</tr>
<tr id="mapBody">
<td colspan="2"><div id="map" style="width: 585px; height: 400px">
</div> </td>
</tr>
</table>
</div>
</div>
with the backside code
public partial class GetDrivingDirections : CMSAbstractWebPart
{
public string compname { get; set; }
public string address { get; set; }
public string phonenum { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (GetValue("name") != null)
{
compname = GetValue("name").ToString();
}
else
{
compname = "";
}
if (GetValue("address") != null)
{
address = GetValue("address").ToString();
}
else
{
address = "";
}
if (GetValue("phonenum") != null)
{
phonenum = GetValue("phonenum").ToString();
}
else
{
phonenum = "";
}
name.Value = compname;
addr.Value = address;
phone.Value = phonenum;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
Response.Redirect("GetDrivingDirections2.aspx?name=" + name.Value + "&addr=" + addr.Value + "&phone=" + phone.Value + "&destaddr=" + fromAddress.Value);
}
}
The second control is as follows
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="goDrivingDirections.ascx.cs" Inherits="CMSApp.CMSWebParts.RohlWebParts.goDrivingDirections" %>
<script type="text/javascript">
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var oldDirections = [];
var currentDirections = null;
var name;
var addr;
var phone;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(0, 0);
var mapOptions = {
zoom: 12,
center: latlng,
navigationControl: true,
navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL },
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
name = document.getElementById("p_lt_ctl00_goDrivingDirections_name").value;
addr = document.getElementById("p_lt_ctl00_goDrivingDirections_addr").value;
phone = document.getElementById("p_lt_ctl00_goDrivingDirections_phone").value;
var contentstring = createHTMLNode(name + '<br/>Address: ' + addr + '<br/>Phone: ' + phone);
var infowindow = new google.maps.InfoWindow({
content: contentstring
});
directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setPanel(document.getElementById('directions'));
calcRoute();
//document.getElementById("showroomContainer").innerHTML = '<span class="nameSpan">' + name + '</span><br/><span class="addrSpan">Address: ' + addr + '</span>' + '</span><br/><span class="phoneSpan">Phone: ' + phone + '</span>';
//setDirections("San Francisco", addr, "en_US");
}
function calcRoute() {
var start = document.getElementById("p_lt_ctl00_goDrivingDirections_fromAddress").value;
var end = document.getElementById("p_lt_ctl00_goDrivingDirections_addr").value;;
var waypts = [];
var request = {
origin:start,
destination:end,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
//function calcRoute() {
// document.getElementById("directions").innerHTML = "";
// document.getElementById("dirHeader").style.display = "";
// document.getElementById("dirBody").style.display = "";
// document.getElementById("mapBody").style.display = "none";
// d
// var request = {
// origin: start,
// destination: end,
// travelMode: google.maps.DirectionsTravelMode.DRIVING
// };
// directionsService.route(request, function (response, status) {
// if (status == google.maps.DirectionsStatus.OK) {
// directionsDisplay.setDirections(response);
// }
// });
//}
function createHTMLNode(text) {
try {
var n = document.createElement('div');
n.setAttribute('style', 'width:250px; font-weight:bold;text-align:left;padding-top:10px; font-size:10px;')
if (n.style) {
n.style.fontWeight = 'bold';
n.style.textAlign = 'left';
n.style.width = '250px';
n.style.paddingTop = '10px';
n.style.fontSize = '10px';
}
if (text)
n.innerHTML = text;
return n;
}
catch (e) {
}
}
function qparam(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div style="width:100%;">
<form action="#" >
<input type="hidden" id="name" name="name" runat="server"/>
<input type="hidden" id="addr" name="addr" runat="server" />
<input type="hidden" id="addrLatLng" name="addrLatLng" runat="server" />
<input type="hidden" id="phone" name="phone" runat="server" />
<input type="hidden" id="destaddr" name="destaddr" runat="server" />
<table style="width: 100%;" cellpadding="0" cellspacing="0">
<tbody>
<tr >
<td width="49%"/>
<td nowrap="" width="610" style="color: #ffffff; font-weight: normal; font-size: 20px; text-align: left; padding-top: 5px;">
<a name="Top"/>
<table class="header">
<tr>
<td style="width:480px" id="showroomContainer" class="showroomContainer">
ROHL HOSPITALITY PROJECTS
</td>
<td>
<div class="non-printable">
<input type="button" onclick="window.print(); return false;" value="Print"/>
</div>
</td>
<td>
<div class="non-printable">
<input type="button" onclick="javascript: window.close(); return false;" value="Close"/>
</div>
</td>
</tr>
</table>
</td>
<td width="49%"/>
</tr>
</table>
<div style="width:600px; padding:10px 80px 0 80px;">
<table class="directions">
<tr>
<!--<td valign="top"><div id="emptyDiv" style="width: 275px;"> </div></td>-->
<td valign="top" align="left" style="font-family:'Times New Roman', Times, serif; font-size:16px; color:#802719; font-weight:bold;" colspan="2"><div id="fromContainer" class="non-printable" style="width: 100%;">Please enter your starting address for custom driving directions: </div></td>
</tr>
<tr>
<td>
<input class="non-printable" type="text" id="fromAddress" size="25" style="width:522px;"/>
</td>
<td>
<input class="submit non-printable" id="submit" type="submit" value="Submit"/>
</td>
</tr>
</table>
</form>
<br/>
<table class="directions">
<tr id="dirHeader" ><th>Directions</th><th>Map</th></tr>
<tr id="dirBody" >
<td valign="top"><div id="directions" style="width: 275px"></div></td>
<td valign="top"><div id="map_canvas" style="width: 310px; height: 400px"></div></td>
</tr>
</table>
</div>
</div>
and the backside code
public partial class goDrivingDirections : CMSAbstractWebPart
{
public string compname { get; set; }
public string address { get; set; }
public string phonenum { get; set; }
public string destAddr { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (GetValue("name") != null)
{
compname = GetValue("name").ToString();
}
else
{
compname = "";
}
if (GetValue("address") != null)
{
address = GetValue("address").ToString();
}
else
{
address = "";
}
if (GetValue("phonenum") != null)
{
phonenum = GetValue("phonenum").ToString();
}
else
{
phonenum = "";
}
if (GetValue("destaddr") != null)
{
destAddr = GetValue("destaddr").ToString();
}
else
{
destAddr = "";
}
name.Value = compname;
addr.Value = address;
phone.Value = phonenum;
destaddr.Value = destAddr;
}
}
Again I am able to see the Map in the first page but I am unable to get directions.
Thanks,
Roy VanderPloeg