This is my code to calculate distance between two address and if it
searches the address then it calculates,other wise it takes co-
ordinates which user pin-point while making address.This is my code
sometimes its works,but some times it dispaly error
"An unknown error occurred"
why??????????????????????????
<script language="javascript"><!--
var selected;
function selectRowEffect(object, buttonSelect) {
if (!selected) {
if (document.getElementById) {
selected = document.getElementById('defaultSelected');
} else {
selected = document.all['defaultSelected'];
}
}
if (selected) selected.className = 'moduleRow';
object.className = 'moduleRowSelected';
selected = object;
// one button is not an array
if (document.checkout_payment.payment[0]) {
document.checkout_payment.payment[buttonSelect].checked=true;
} else {
document.checkout_payment.payment.checked=true;
}
}
function rowOverEffect(object) {
if (object.className == 'moduleRow') object.className =
'moduleRowOver';
}
function rowOutEffect(object) {
if (object.className == 'moduleRowOver') object.className =
'moduleRow';
}
//--></script>
<script language="JavaScript" type="text/javascript">
var sendReq = getXmlHttpRequestObject();
var receiveReq = getXmlHttpRequestObject();
var receiveReqInfoBox = getXmlHttpRequestObject();
var file = 'getCart.php';
var loc = 'span_cart';
var tmp = ' <img src=images/loading_sc.gif
alt=loading> <?
echo(MESAGE_WAIT)?><br/>';
//Function for initializating the page.
function startCart(key,file,sid,loc,tmp) {
initialize();
load();
//Start Showing Cart.
getCartText('',file,sid,loc,tmp);
}
//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
<?php
define('SHOW_NON_AJAX_CART',false); ?>
return new XMLHttpRequest();
} else if(window.ActiveXObject) {
<?php define('SHOW_NON_AJAX_CART',false); ?>
return new
ActiveXObject("Microsoft.XMLHTTP");
} else {
document.getElementById('p_status').innerHTML = 'Status: Cound
not create XmlHttpRequest Object. Consider upgrading your browser.';
<?php
define('SHOW_NON_AJAX_CART',true); ?>
}
}
//Gets the current cart
function getCartText(key,file,sid,loc,tmp) {
var url=file+"?"+sid+"&"+key;
if (sid && key) {
url=file+"?"+sid+"&"+key;
} else {
if (sid) {
url=file+"?"+sid;
} else {
if (key) {
url=file+"?"+key;
} else {
url=file;
}
}
}
if (tmp) {getObject(loc).innerHTML = tmp;}
if (receiveReq.readyState == 4 ||
receiveReq.readyState == 0) {
receiveReq.open("GET", url+'&Cart=1',
true);
receiveReq.onreadystatechange =
handleReceiveCart;
receiveReq.send(null);
}
}
//Gets the current cart info box
function getCartInfoBoxText(key,file,sid,loc,tmp) {
var url=file+"?"+sid+"&"+key;
if (sid && key) {
url=file+"?"+sid+"&"+key;
} else {
if (sid) {
url=file+"?"+sid;
} else {
if (key) {
url=file+"?"+key;
} else {
url=file;
}
}
}
if (tmp) {getObject(loc).innerHTML = tmp;}
if (receiveReqInfoBox.readyState == 4 ||
receiveReqInfoBox.readyState == 0) {
receiveReqInfoBox.open("GET",
url+'&Cart=1', true);
receiveReqInfoBox.onreadystatechange =
handleReceiveCartInfoBox;
receiveReqInfoBox.send(null);
}
}
//send change of stock to Cart.
function sendCartChangeQty
(key,file,sid,loc,tmp,iElementId,product_id,qty) {
if (typeof iElementId == "string" && iElementId.length
> 0) {
var element =
document.getElementById(iElementId);
if (element) {
//alert("name=" + element.name + " - id=" +
element.id);
//return;
} else {
document.getElementById('p_status').innerHTML =
'Status: Could not find the requested element.';
return;
}
}
//Verify entered quantity is number
if (isNaN(element.value)) {
document.getElementById('p_status').innerHTML =
'You must enter a
number for Quantity.';
getCartText(key,file,sid,loc,tmp);
return;
}
else {
document.getElementById('p_status').innerHTML =
'';
}
// check if Quantity drops below 0
// check if Quantity drops below 0
if (Number(element.value) + Number(qty) <= 0) {
//Call function to delete item
sendCartRemoveItem(key,file,sid,loc,tmp,iElementId,product_id);
return;
}
var url=file+"?"+sid+"&"+key;
if (sid && key) {
url=file+"?"+sid+"&"+key;
} else {
if (sid) {
url=file+"?"+sid;
} else {
if (key) {
url=file+"?"+key;
} else {
url=file;
}
}
}
if (tmp) {getObject(loc).innerHTML = tmp;}
if (sendReq.readyState == 4 ||
sendReq.readyState == 0) {
sendReq.open("POST", url+'&Cart=1',
true);
sendReq.setRequestHeader('Content-Type','application/x-www-form-
urlencoded');
sendReq.onreadystatechange =
handleSendCart;
var param = 'quantity=' +
(Number(element.value) + Number(qty));
param += '&products_id=' + product_id;
sendReq.send(param);
}
}
//send change of stock to Cart.
function sendCartRemoveItem
(key,file,sid,loc,tmp,iElementId,product_id) {
if (typeof iElementId == "string" && iElementId.length
> 0) {
var element =
document.getElementById(iElementId);
if (element) {
//alert("name=" + element.name + " - id=" +
element.id);
//return;
} else {
document.getElementById('p_status').innerHTML =
'Status: Could not find the requested element.';
return;
}
}
// check user wants to remove item
//if (element.value != '') {
// Are you sure you want to remove this item
var fRet;
fRet = confirm('Are you sure you want to remove
this item from
your shopping cart?');
//alert(fRet);
if (fRet == false) {
getCartText(key,file,sid,loc,tmp);
return;
}
var url=file+"?"+sid+"&"+key;
if (sid && key) {
url=file+"?"+sid+"&"+key;
} else {
if (sid) {
url=file+"?"+sid;
} else {
if (key) {
url=file+"?"+key;
} else {
url=file;
}
}
}
if (tmp) {getObject(loc).innerHTML = tmp;}
if (sendReq.readyState == 4 ||
sendReq.readyState == 0) {
sendReq.open("POST", url+'&Cart=1',
true);
sendReq.setRequestHeader('Content-Type','application/x-www-form-
urlencoded');
sendReq.onreadystatechange =
handleSendCartRemoveItem;
var param = '&products_id=' +
product_id;
param += '&cart_delete=Yes';
sendReq.send(param);
}
}
//When our stock change has been sent, update our page.
function handleSendCart() {
if (sendReq.readyState == 4 && sendReq.status == 200){
getCartText('','getCart.php','<?php echo
tep_session_name
().'='.tep_session_id(); ?>','span_cart',tmp);
getCartInfoBoxText('','getCartBox.php','<?php echo
tep_session_name
().'='.tep_session_id(); ?>','span_cart_box',tmp);
}
}
//Function for handling the return of Cart text
function handleReceiveCart() {
//Check to see if the XmlHttpRequests state is
finished.
if (receiveReq.readyState == 4) {
//Set the contents of our span element
to the result of the
asyncronous call.
document.getElementById('span_cart').innerHTML =
receiveReq.responseText;
}
}
//Function for handling the return of Cart Info Box text
function handleReceiveCartInfoBox() {
//Check to see if the XmlHttpRequests state is
finished.
if (receiveReqInfoBox.readyState == 4) {
//Set the contents of our span element
to the result of the
asyncronous call.
document.getElementById('span_cart_box').innerHTML =
receiveReqInfoBox.responseText;
}
}
//When our stock change has been sent, update our page.
function handleSendCartRemoveItem() {
if (sendReq.readyState == 4 && sendReq.status == 200){
getCartText('','getCart.php','<?php echo
tep_session_name
().'='.tep_session_id(); ?>',loc,tmp);
getCartInfoBoxText('','getCartBox.php','<?php echo
tep_session_name
().'='.tep_session_id(); ?>','span_cart_box',tmp);
}
}
function getObject(name) {
var ns4 = (document.layers) ? true : false;
var w3c = (document.getElementById) ? true : false;
var ie4 = (document.all) ? true : false;
if (ns4) return eval('document.' + name);
if (w3c) return document.getElementById(name);
if (ie4) return eval('document.all.' + name);
return false;
}
</script>
<script src="http://maps.google.com/maps?
file=api&v=2&key=ABQIAAAAXpjGkPlX9gz3VRY-
R7akKxS9e0Y_J9MwmMRPF6V5TlFJONR1vRRtdee7lVE-FFLHmKQTagueKgVUcQ"
type="text/javascript"></script>
<script src="jquery-1.2.1.pack.js"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var map;
var gdir;
var geocoder = null;
var addressMarker;
// define variable from PHP and bring into JS
var storeAddress = "<?php echo $entry_street_address ?>";
var latlon1= "<?php echo $latlon1 ?>";
var deliveryAddress = "<?php echo $deliveryAddress ?>";
var latlon2= "<?php echo $latlon2 ?>";
var deliveryName = "<?php echo $deliveryName ?>";
function initialize() {
if (GBrowserIsCompatible()) {
//build map
gdir = new GDirections();
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);
setDirections(storeAddress, deliveryAddress, "en_US");
}
}
function setDirections(fromAddress, toAddress, locale) {
gdir.load("from: " + fromAddress + " to: " + toAddress,
{ "locale": locale });
}
function handleErrors(){
if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
setDirections(latlon1, latlon2, "en_US");
else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
alert("A geocoding or directions request could not be
successfully processed, yet the exact reason for the failure is not
known.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
alert("The HTTP q parameter was either missing or had no value.
For geocoder requests, this means that an empty address was specified
as input. For directions requests, this means that no query was
specified in the input.\n Error code: " + gdir.getStatus().code);
// else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS) <---
Doc bug... this is either not defined, or Doc is wrong
// alert("The geocode for the given address or the route for the
given directions query cannot be returned due to legal or contractual
reasons.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_KEY)
alert("The given key is either invalid or does not match the
domain for which it was given. \n Error code: " + gdir.getStatus
().code);
else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
alert("A directions request could not be successfully parsed.\n
Error code: " + gdir.getStatus().code);
else alert("An unknown error occurred.");
}
function onGDirectionsLoad(){
var range_km = "<?php echo $range_km ?>";
var price_km = "<?php echo $price_km ?>";
var Minperkm = "<?php echo $Minperkm ?>";
var drivingDistanceKilometers = gdir.getDistance().meters / 1000;
alert(drivingDistanceKilometers);
/*if(drivingDistanceKilometers<range_km){ */
var price_distance=price_km*drivingDistanceKilometers;
var timed=Minperkm*drivingDistanceKilometers;
var price_distance2=price_distance;
document.price.price_distance1.value = price_distance2;
document.price.Minperkm.value = timed;
// $.post("shopping_cart.php", $("#frm").serialize());
/*$.post("test1.php", $("#frm").serialize(), function(data){
if(data) {
}else{
alert('no post');
}
});
*/
/*}
else
{
alert("Our resturant is out of range sorry we cant deliver food to
that address")
}*/
// Use this function to access information about the latest load
()
// results.
// e.g.
// document.getElementById("getStatus").innerHTML =
gdir.getStatus().code;
// and yada yada yada...
}
</script>
<!-- EOE: ERSD.net AJAX Shopping Cart -->
<script type="text/javascript">
<!--
on = "<?php echo TEXT_SHOPPINGCART_UPDATE; ?>";
off = " ";
function advisecustomer(advise_status) {
document.cart_quantity.advise.value = advise_status;
}
-->
</script>
<script src="http://maps.google.com/maps?
file=api&v=2&key=ABQIAAAAXpjGkPlX9gz3VRY-
R7akKxRmzKHMkjVPxcoSHeun1t4aIEbkfhT_TNpKE2fZPgcTtaYZKragc10r9w"
language="javascript"></script>
<script language="javascript"><!--
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
var center = new GLatLng(39.90817, 116.39795);
map.setCenter(center, 15);
geocoder = new GClientGeocoder();
var marker = new GMarker(center, {draggable: true});
map.addOverlay(marker);
document.getElementById("lat").innerHTML = center.lat().toFixed
(5);
document.getElementById("lat").value= center.lat().toFixed(5);
document.getElementById("lng").value= center.lng().toFixed(5);
document.getElementById("lng").innerHTML = center.lng().toFixed
(5);
GEvent.addListener(marker, "dragend", function() {
var point = marker.getPoint();
map.panTo(point);
document.getElementById("lat").innerHTML = point.lat().toFixed
(5);
document.getElementById("lng").innerHTML = point.lng().toFixed
(5);
document.getElementById("lat").value = point.lat().toFixed(5);
document.getElementById("lng").value = point.lng().toFixed(5);
});
GEvent.addListener(map, "moveend", function() {
map.clearOverlays();
var center = map.getCenter();
var marker = new GMarker(center, {draggable: true});
map.addOverlay(marker);
document.getElementById("lat").innerHTML =
center.lat().toFixed
(5);
document.getElementById("lng").innerHTML = center.lng().toFixed
(5);
document.getElementById("lat").value = center.lat().toFixed(5);
document.getElementById("lng").value = center.lng().toFixed(5);
flag = 1;
GEvent.addListener(marker, "dragend", function() {
var point =marker.getPoint();
map.panTo(point);
document.getElementById("lat").innerHTML = point.lat().toFixed
(5);
document.getElementById("lng").innerHTML = point.lng().toFixed
(5);
document.getElementById("lat").value = point.lat().toFixed(5);
document.getElementById("lng").value = point.lng().toFixed(5);
});
});
}
}
function showAddress(address) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
document.getElementById("lat").innerHTML =
point.lat().toFixed(5);
document.getElementById("lng").innerHTML = point.lng().toFixed(5);
map.clearOverlays()
map.setCenter(point, 14);
var marker = new GMarker(point, {draggable: true});
map.addOverlay(marker);
GEvent.addListener(marker, "dragend", function() {
var pt = marker.getPoint();
map.panTo(pt);
document.getElementById("lat").innerHTML = pt.lat().toFixed(5);
document.getElementById("lng").innerHTML = pt.lng().toFixed(5);
});
GEvent.addListener(map, "moveend", function() {
map.clearOverlays();
var center = map.getCenter();
var marker = new GMarker(center, {draggable: true});
map.addOverlay(marker);
document.getElementById("lat").innerHTML =
center.lat().toFixed
(5);
document.getElementById("lng").innerHTML = center.lng().toFixed
(5);
GEvent.addListener(marker, "dragend", function() {
var pt = marker.getPoint();
map.panTo(pt);
document.getElementById("lat").innerHTML = pt.lat().toFixed(5);
document.getElementById("lng").innerHTML = pt.lng().toFixed(5);
});
});
}
}
);
}
}
//--></script>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en
-~----------~----~----~----~------~----~------~--~---