latitude longitude component

1. Senior Member
Join Date
Dec 1969
Posts
666

## latitude longitude component

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## latitude/longitude of *WHAT*???

Tsunami warning buoys in the Pacific Ocean?<BR><BR>Inflection points in maps of all the world&#039;s countries accurate to 10 meters?<BR><BR>What do you expect such a component to *DO*?<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
666

## Oops... Sorry...

Of all the city in the US. <BR>I have a dataase with all the cities,states,zip codes,latitude and longitude in the US.<BR><BR>I wanna write a zip code and choose a number of radius around it and get the the list of cities for example.

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Good...there was a long...

...discussion of this in the Advanced forum a few months back.<BR><BR>Try look for posts by me in Advanced, with "zip code" in the text of the post, and you&#039;ll find it.<BR><BR>You don&#039;t need any component. A simple SQL query combined, possibly, with a small bit of VBS code is all you need.<BR><BR>So long as the radius you choose is, say, 100 miles or so, then the simple Pythagorean Theorem will give an accurate enough anser, so long as you adjust the longitude conversion to miles in a way that compensates for the latitude.<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Good...there was a long...

...discussion of this in the Advanced forum a few months back.<BR><BR>Try look for posts by me in Advanced, with "zip code" in the text of the post, and you&#039;ll find it.<BR><BR>You don&#039;t need any component. A simple SQL query combined, possibly, with a small bit of VBS code is all you need.<BR><BR>So long as the radius you choose is, say, 100 miles or so, then the simple Pythagorean Theorem will give an accurate enough anser, so long as you adjust the longitude conversion to miles in a way that compensates for the latitude.<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
666

## I found something...

http://www.aspmessageboard.com/forum/showMessage.asp?F=27&M=713902&P=1#713553<BR><BR>Bu t the problem is that I really don&#039;t know how to get this thing working.<BR><BR>I wish I could write like this by myslef but it&#039;s way to complicated for me.

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## Okay, let's take a stab at it...

&nbsp;<BR>The first thing to realize is that the number of miles in one degree of longitude is variable! Near the equator, it&#039;s (roughly) the same as the number of miles in a degree of latitude. Near either pole, it approaches zero. (If you are one foot from the North pole, then all 360 degrees can be traversed by walking in a circle with a circumference of 6.28 feet!)<BR><BR>So it&#039;s just a matter of a little bit of trigonometry.<BR><BR>How many miles in one degree of longitude at any given latitude?<BR><BR>Why 1/360 of the circumference of the earth at that latitude.<BR><BR>And what is the circumference of the earth at any given latitude?<BR><BR>Well, obviously 2 times PI times the radius of the earth.<BR><BR>So, assuming that the radius of the earth at the equator is rougly 3800 miles...<BR><BR> r = 3800 * COS(latitude)<BR><BR>At 0 degrees latitude, COS() is 1.0, so the radius is indeed 3800.<BR><BR>At 90 degrees latitude, COS() is 0.0, so the radius is zero.<BR><BR>So the number of miles in a degree of longitude is:<BR> ( 3800 * COS(latitude) * 2 * PI ) / 360<BR><BR>And of course we can factor out all the constants to get:<BR> COS(latitude) * ( 3800 * 2 * PI / 360 )<BR>which is roughly<BR> COS(latitude) * 67<BR><BR>Of course, the number of mile in a degree of latitude is just 67, no matter the latitude nor longitude.<BR><BR>So to get the number of miles between two points:<BR><BR>Say: <BR> LA1 and LO1 are the LAtitude and LOngitude of point 1<BR> LA2 and LO2 are the LAtitude and LOngitude of point 2<BR><BR>Assuming that the distance between the two points is no more than a couple of hundred miles or so, we can just get the number of miles per degree of longitude from one of the two points, so:<BR><BR> MPDLo = 67 * COS(LA1) &#039; miles per degree of longitude<BR> LoDiff = LO1 - LO2 &#039; diff in degrees between the points, longitude<BR> MLoDiff = LoDiff * MPDLo &#039; diff in miles between the points, longitude<BR> LaDiff = LA1 - LA2 &#039; diff in degrees, latitude<BR> MLaDiff = LaDiff * 67 &#039; diff in miles, latitude<BR> Distance = SQR( MLoDiff * MLoDiff + MLaDiff * MLaDiff ) &#039; pythagorean theorem<BR><BR>[SQR is the SQuare Root function.]<BR><BR>Again, since we are on the surface of a sphere (okay, on an oblate spheroid), we should use a more complicated solid geometry formula to get the distance, but the inherent inaccuracy in zip code latitude/longitude numbers is more than the error we get from using the simplified form.<BR><BR>Does that get you started?<BR><BR><BR><BR><BR>

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## Forgot to note...

I wrote that as<BR> COS(LA1)<BR>but LA1 is in degrees and the COS( ) function in most systems requires its argument to be in radians.<BR><BR>So you&#039;d need to do <BR> COS( LA1 * 3.14159265 / 180 )<BR><BR>Finally, you *COULD* build that distance calculation all into a single expression, so you *COULD* use it in a SQL query:<BR><BR>SQR( ( (LO1 - LO2) * 67 * COS(LA1 * 0.01745) ) ^ 2 + ( (LA1 - LA2) * 67 ) ^ 2 )<BR><BR>Untested, but feels right.<BR><BR><BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•