Newbie Question: calculating distances with mappoint given zip codes

Microsoft MapPoint

Newbie Question: calculating distances with mappoint given zip codes

Hello. I am an mp newbie. I am fixing an existing .NET application that
calls our map point server to retrieve custom regions. Here is my issue:

We call the map point server with a zip code and it returns
latitude/longitude coordinates. with the following code:

double lat=0.0;
double lon=0.0;
com.ourserver.mapping.LatLong oLatLong = new
oLatLong.Url = "";
oLatLong.GetLatLong("", "", "", zip, "US", ref lat, ref lon);

Now we have the latitude and longitude of our client. The next step is
to find regions within 100 miles of the client. We have these setup in
the db. The code is as follows:

if ((lat!= 0) && (lon!=0))
double latstart=0, latend=0, lonstart=0, lonend=0;
double latstart1=0, latend1=0, lonstart1=0, lonend1=0;
double temp = this.AngularRadius(160);
latstart = lat-((temp*3.14*6378/180)/111.3171);
latend = lat+((temp*3.14*6378/180)/111.3171);
lonstart = lon -((temp*3.14*6378/180)/55.658);
lonend = lon + ((temp*3.14*6378/180)/55.658);
latstart1 = lat-temp;
latend1 = lat+temp;
lonstart1 = lon-temp;
xSql = "select distinct u.regionid, u.region from region u, regionzip
z where u.affiliateid is null and u.regionid=z.regionid and"
+ " z.latitude between " + latstart1 + " and " + latend1
+ " and z.longitude between " + lonstart1 + " and " + lonend1
+ " and z.latitude between " + latstart + " and " + latend
+ " and z.longitude between " + lonstart + " and " + lonend;
tbl = DataAccess.Query(Application["ConnectString"].ToString(), xSql,
if (tbl != null)
found = true;
for (int k = 0; k < tbl.Rows.Count; k++)
region = Web.BuildOptionListFromTable(tbl, "regionid", "region", "");
found = false;

This works MOST of the time and hence my question: Some (not many) US
zip codes do not return a result set from the database query, others
return a wrong result set, presenting an incorrect region. The error
occurs consistently with a couple of zip codes. Is this something that
is a known issue in MP or have other people come across similar
behaviors? If anyone has done something similar and could post an
alternate routine (C# preferred) to the one we are using (I didn't write
it myself, been too long since I did spherical geometry or F&R, can't
find my old textbooks...). Or, if you are math God, please tell me what
this wrong with this code. Thx in advance!

BogeyBoy sez... Fore!
Another thing. Our regions are stored in the db by lat/long coodinates.
So, after we reveive the mappoint lat/long for the client's location, we
are then restricting the returned regions to those whose lat/long
coordinates are within the desired 100 mile radius. Thx again!