Hi

Thanks for your reply. I am sending my code.
Please suggest me if anything is wrong in code

Function to calculate distance

function caldis($addr,$addr1)
{
require_once('lib/GoogleMapAPI.class.php');

$map = new GoogleMapAPI('map');
$map->setAPIKey('ABQIAAAAE-W_Pw2S_cQFTXQPeqAN5hSRhJXTRu3fM0ElVXnwviTojdgwfBSFyasfUJBRe0fV-qRt2uYLyHYkbA');
$geocode = $map->geoGetCoords($addr);
    //print_r($geocode);
$lat=    $geocode['lat'];
$lon=    $geocode['lon'];


$geocode = $map->geoGetCoords($addr1);

$lat1=    $geocode['lat'];
$lon1=    $geocode['lon'];
/*echo $addr.$addr1;
echo $lat.$lon.$lat1.$lon1;*/
    //M-Miles
$distance = $map->geoGetDistance($lat,$lon,$lat1,$lon1,M);
return $distance;
}



Google map Javascript-- display map and direction

<script language="javascript" type="text/javascript">
  var geocoder = null;
  var map;
  var gdir;
  var addressMarker;

 function handleErrors(){
       if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
         alert("No corresponding geographic location could be found for one
of the specified addresses. This may be due to the fact that the address is
relatively new, or it may be incorrect.\nError code: " +
gdir.getStatus().code);
       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(){
      // Use this function to access information about the latest load()
      // results.

      // e.g.
      // document.getElementById("getStatus").innerHTML =
gdir.getStatus().code;
      // and yada yada yada...
    }

    function setDirections(fromAddress, toAddress, locale) {

      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }

  function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl (new GSmallMapControl());
map.addControl(new GMapTypeControl());
var center = new GLatLng(-22.98699983834975, -43.210344314575195);

map.setCenter(center, 11);

geocoder = new GClientGeocoder();

var marker = new GMarker(center, {draggable: true});
map.addOverlay(marker);
document.getElementById("lat").value = center.lat();
document.getElementById("lng").value = center.lng ();

geocoder = new GClientGeocoder();

GEvent.addListener(marker, "dragend", function() {
var point =marker.getPoint();
map.panTo(point);
document.getElementById("lat").value = point.lat();
document.getElementById("lng").value = point.lng();
});

GEvent.addListener(map, "moveend", function() {
map.clearOverlays();
var center = map.getCenter();
var marker = new GMarker(center, {draggable: true});
map.addOverlay(marker);

document.getElementById ("lat").value = center.lat();
document.getElementById("lng").value = center.lng();

GEvent.addListener(marker, "dragend", function() {
var point =marker.getPoint();
map.panTo(point);
document.getElementById("lat").value = point.lat();
document.getElementById("lng").value = point.lng();
});
});
}

}
function showdirection(frm) {

geocoder = new GClientGeocoder();

var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());


if (geocoder) {
geocoder.getLatLng (
frm.addr.value,
function(point) {
if (!point) {
alert(frm.addr.value + " city not found !");
}
else {

map.setCenter(point, 12);

var marker = new GMarker(point, {draggable: true});
map.addOverlay(marker);
GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(frm.addr.value);});
         //marker.openInfoWindowHtml(frm.addr.value);
}}
);


geocoder.getLatLng (
frm.addr1.value,
function(point) {
if (!point) {
alert(frm.addr1.value + " city not found !");
}
else {

var marker1 = new GMarker(point, {draggable: true});
map.addOverlay(marker1);
GEvent.addListener(marker1, "click", function() {
            marker1.openInfoWindowHtml(frm.addr1.value);});


}}
);
if (GBrowserIsCompatible()) {


        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

        setDirections(frm.addr.value,frm.addr1.value, "en_US");
      }

}
}




Thanks and Regards
Sheetal

On Fri, Sep 5, 2008 at 10:16 AM, Mike Williams <[EMAIL PROTECTED]>wrote:

>
> One possibility is that the driving distance between two points is
> likely to be longer than the straight line distance.
>
> Another possibility is that your distance calculation code is wrong.
>
> Another possibility is that your lat/lng values don't exactly match the
> addresses.
> --
> http://econym.googlepages.com/index.htm
> The Blackpool Community Church Javascript Team
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to