View Full Version : converting numbers so they represent distance.

07-02-2005, 10:25 PM
I'm stuck here both in terms of how to think it through and then, how to write it :eek:

edit: just had inspiration as I re-read this... is it as simple as finding out how many 'numbers' there are per kilometres and, then changing the line
$distanceEastWest = ($baseEastings - $nearbyEastings); TO
$distanceEastWest = ($baseEastings - $nearbyEastings / 10);

ie, divide by 10 if there are ten to the Km?


my $clientGrid = "34567898";

my ( $baseNorthings , $baseEastings ) = ($clientGrid =~ /(....)/g);

baseNorthing is therefore 3456
baseEasting is therefore 7898

That bit is OK but then I use the code

my $nearbyEastings = "34567890";
my $nearbyNorthings = "45678987";

$distanceEastWest = ($baseEastings - $nearbyEastings);
if ($baseEastings > $nearbyEastings) {
print <<EOF;
$business is $distanceEastWest West of $clientBusiness
} elsif ($baseEastings < $nearbyEastings) {
print <<EOF;
$business is $distanceEastWest East of $clientBusiness
} elsif ($baseNorthings == $nearbyNorthings) {
print <<EOF;
This $businessType is on the same Northing as $clientBusiness

This simply ads and subtracts the portions of numbers and prints the numerical difference between them.

I need to find out how to convert the difference between the numbers (not necessarily the numbers themselves), to be able to print
This $businessType is XX kilometres East/West/North/South of $clientBusiness


Please if any of you can give me a tip or hint, I'll be a happy teddy bear.


07-02-2005, 11:35 PM
Bazz ...

I can't find any examples at the moment, but what people are doing in the U.S. is actually entering GPS coordinates for businesses and locations.

Using mathematics with the Longitude and Latitude to come up with an exact distance (in a straight line). A "fudge-factor" is added if the known distance is not a direct route, or several way-points are calculated.

This is very similar to the U.S. zipcode database that also had GPS coordinates for geographical city centers.

I'm guessing your businesses don't know their exact GPS location, but they can probably find out the coordinates for their city and that might be close enough.

Just an idea ... -max-

Bazz ... I found this: http://www.zipcodeworld.com/samples/distance.pl.html


07-03-2005, 04:45 PM
Hey Max thanks.

After I posted last night, I went back to the 'olde worlde' pen and paper type devices. I remembered some mathematics from an earlier era which has helped. GPS isn't guaranteed accurate yet in my country and whilst I don't know if it ever will be, I think that the solution I have found is sufficient for now, for what I am doing.

Of course I have to contend too, with the reality that the southern 3/4 of this land mass doesn't use post/Zip codes :eek: :rolleyes: and I need a consistent sytem.

Ho Hum :)