[mapguide-users] Calculating a Euclidean Distance in Javascript

Bruce Dechant bruce.dechant at autodesk.com
Wed May 21 13:21:00 EDT 2008


This is the exact code that is being executed by the MeasureEuclideanDistance API:

double CCoordinateSystem::MeasureEuclideanDistance(double x1, double y1, double x2, double y2)
{
    double distance = 0.0;

    MG_TRY()
    distance = ::sqrt(::pow(x1 - x2, 2.0) + ::pow(y1 - y2, 2.0));
    MG_CATCH_AND_THROW(L"MgCoordinateSystem.MeasureEuclideanDistance")

    return distance;
}

Hope this helps.

Bruce

-----Original Message-----
From: mapguide-users-bounces at lists.osgeo.org [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of nclayton
Sent: Tuesday, May 20, 2008 1:27 PM
To: mapguide-users at lists.osgeo.org
Subject: [mapguide-users] Calculating a Euclidean Distance in Javascript


I'm trying to reproduce the function being called in php to measure the
distance between the two points of the measure tool in javascript so that I
can display the current distance while a user is picking a second point on
the map. So far the formula I have tried is not producing the same result as
the result of
$srsMap->MeasureEuclideanDistance($x1,$y1,$x2,$y2) in measure.php

the formula I am trying is:
distance = sqrt(abs(x2 - x1)^2 + abs(y2-y1)^2)

then to convert to miles:
miles = distance * 0.000621371192

Thanks in advance for any input.
--
View this message in context: http://www.nabble.com/Calculating-a-Euclidean-Distance-in-Javascript-tp17348713p17348713.html
Sent from the MapGuide Users mailing list archive at Nabble.com.

_______________________________________________
mapguide-users mailing list
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users


More information about the mapguide-users mailing list