close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Driving directions to either of two addresses

Thread began 3/01/2010 4:50 am by gwh362692 | Last modified 3/15/2010 4:46 pm by Eric Mittman | 1812 views | 14 replies |

gwh362692

Driving directions to either of two addresses

Hi everyone,

If I have two addresses on my google map, is it possible to allow the user to put in a start address and allow them to choose which destination they want to go to, ie. either one of the two addresses?

If yes, is there a set of instructions on how to do this?

Thanks

Sign in to reply to this post

Eric Mittman

Do you have the two possible destinations in a db table? If so you could have the user fill in a form with their location then choose the destination from a select list on the form. When the page is submitted to itself it will post the id of the selected destination, you can then have another recordset that will select that destination from the db. You would then use this recordsets bindings for the destination location within the Maps interface.

This is not something that we have a specific guide for but it could be done like described above if the destinations are in a table. Let us know if you have any questions about this and we will be glad to help you with whatever we can.

Sign in to reply to this post

gwh362692

Thanks for the reply,

I have a database table called 'locations' which consists of 7 rows as follows:

locationID
store
street
suburb
state
postcode
country

I've created the form that the user fills out. As you suggested, this form also contains a select menu which is being populated with the two store names from my locations table.

I also manually inserted a hidden field in the form as follows but I don't know whether I was supposed to do this via a dialogue box?:

<input type="hidden" name="locationID" value="<?php
echo $row_rstLocations['locationID']; ?>"/>

The following is the sql used for the first query to populate the select menu:

mysql_select_db($database_locations, $locations);
$query_rstLocations = "SELECT locationID, store FROM locations";
$rstLocations = mysql_query($query_rstLocations, $locations) or die(mysql_error());
$row_rstLocations = mysql_fetch_assoc($rstLocations);
$totalRows_rstLocations = mysql_num_rows($rstLocations);

After that I created another recordset with the following sql:

SELECT *
FROM locations
WHERE locationID = $row_rstLocations['locationID']

But I got the following error:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '['locationID'] at line 1"

Can you tell me what I might be doing wrong?

In addition to the above method, I tried assigning the selected destination to a variable as follows:

$location = $_POST['locationID'];

I then tried the following sql syntax:

SELECT *
FROM locations
WHERE locationID = $location

But I got another sql syntax error:

"Unknown column '$location' in WHERE clause"

Any help much appreciated.

Sign in to reply to this post

Eric Mittman

You are very close with what you have now. There are two problems that I can see based on your description. The first thing is that the select list for destination should have the name of the destination as the label, and the id as the value.

When it is like this you will create the recordset based on the posted value like you have done. The difference is that you will need to filter the rs using the DW filter options. When viewing the recordset remove the where clause and go into simple view. In here just select the table and the rows that you want to return, then below this part in the filter section choose to filter the locationID on the form value that holds the locationID. This should be your location select list, just enter the name of it.

When you get it setup like this it should dynamically load the info for the selected destination after the user submits the form.

Sign in to reply to this post

gwh362692

Thanks so much - it's all working really well now. Just one thing: when the map loads initially, it's displaying the Gulf of Mexico for some reason. Is there a way to have it display the first of the locations in the database?

Sign in to reply to this post

Eric Mittman

Is this the same map that you are using the values of the filtered recordset for the destination? If so it might not have a valid location when it loads. If this is the case one think you can do to account for that would be to set the default value of your filter to be a record id from your locations table for the location you would like to see as the default.

If you have it this way already or the setup differs from what I have described please post back and let us know and provide some more details about the situation if needed.

Sign in to reply to this post

gwh362692

I don't know what I did but now when it loads, there is no map appearing initially at all. It's only when you fill in the form and select a destination that the map appears along with the driving instructions.

In step 2 of 5 of the wizard, I have all the addresses populated with the rstDestinations recordset.

  If this is the case one thing you can do to account for that would be to set the default value of your filter to be a record id from your locations table for the location you would like to see as the default.  



How do I do this?

The following is the php code at the top of my document:

<?php require_once('../Connections/locations.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_locations, $locations);
$query_rstLocations = "SELECT * FROM locations ORDER BY store ASC";
$rstLocations = mysql_query($query_rstLocations, $locations) or die(mysql_error());
$row_rstLocations = mysql_fetch_assoc($rstLocations);
$totalRows_rstLocations = mysql_num_rows($rstLocations);

$colname_rstDestination = "-1";
if (isset($_POST['location'])) {
$colname_rstDestination = (get_magic_quotes_gpc()) ? $_POST['location'] : addslashes($_POST['location']);
}
mysql_select_db($database_locations, $locations);
$query_rstDestination = sprintf("SELECT locationID, store, street, suburb, `state`, postcode, Country FROM locations WHERE locationID = %s", GetSQLValueString($colname_rstDestination, "int"));
$rstDestination = mysql_query($query_rstDestination, $locations) or die(mysql_error());
$row_rstDestination = mysql_fetch_assoc($rstDestination);
$totalRows_rstDestination = mysql_num_rows($rstDestination);
?>
Sign in to reply to this post

Eric Mittman

There are a couple of ways you can make this edit. You can either open up the rs and go into advanced view to change the default value for the colname parameter or you can change it directly in the code.

Either way you will need to update -1 value to be an id for the default location in your recordset. Here is the code that you would change directly on the page:

php:
$colname_rstDestination = "-1"; //change the -1 to the id of the default location

if (isset($_POST['location'])) {
  $colname_rstDestination = (get_magic_quotes_gpc()) ? $_POST['location'] : addslashes($_POST['location']);
}
Sign in to reply to this post

gwh362692

Thanks so much - all working great now.

Just one final thing: you have to click the little flag icon that marks the address on the map in order to see the address "callout". Is there a way to have that address appear by default on the map that initially appears - just so they know that they're looking at a map of one of the locations? They may not know that they have to click it either which is why it would be good for it to be shown.

Sign in to reply to this post

Eric Mittman

The info window should open up automatically for you when you see the map load, the line of code that does this is in the wagmp_map_1.php file and looks like this:

php:
marker_0_<?php echo $Recordset1_id?>.openInfoWindowHtml(address_0_<?php echo $Recordset1_id?>.infowindowtext);



It would have your recordsets name in it. If you can post back with this file I can check it to see if this line of code is in there and check why it might not be loading for you. Also, are you just displaying the current default location when the map loads or are you also displaying driving directions when it loads?

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...