mbdunkin
08-15-2005, 10:58 AM
Let me preface this by saying I'm BRAND new when it comes to developing code that interacts with MapPoint, so forgive me if my question is "obvious" to those more experienced. :)
At any rate, I have written a small C# app that takes a street address, city, state, and ZIP as input from a user. When the user clicks a button, the app goes out and finds the location in MapPoint, opens and plots the location on a map, and returns the Lat/Long of the location to the app.
If MapPoint finds an exact match for the location as input by the user, then it returns the Lat/Long values fine. However, if it doesn't find an exact match, I have it opening the 'ShowFindDialog' box. At this point, the user may click on an address in the returned list. What I'm having problems with at this point is having it return the Lat/Long of the selected address to my app.
Basically, I don't know how to get the results of what the user selected in the Dialog Box and do my Lat/Long calculation.
Below is the snippet of code that I'm using to calculate the Lat/Long ...
if ( MapPoint.GeoFindResultsQuality.geoFirstResultGood == oResults.ResultsQuality)
{
IEnumerator at = oResults.GetEnumerator();
if ( !at.MoveNext())
{
return null;
}
oLocate = (MapPoint.Location) at.Current;
}
else
{
//If no exact match found, open Dialog box
oMap.ShowFindDialog(strAddress, new MapPoint.GeoFindState(), (int)this.Handle, false);
return null;
}
oLocate.GoTo();
int x;
int y;
double dblLat;
double dblLon;
double l;
double d;
x = oMap.LocationToX(oLocate);
y = oMap.LocationToY(oLocate);
MapPoint.FindResults oContext;
oContext = oMap.ObjectsFromPoint( x, y);
MapPoint.Location obj;
if ( locNorthPole == null )
{
locNorthPole = oMap.GetLocation( 90, 0, 1 );
locSantaCruz = oMap.GetLocation( 0, -90, 1 );
// Compute distance between north and south poles == half earth circumference
dblHalfEarth = oMap.Distance( locNorthPole, oMap.GetLocation(-90, 0, 1) );
// Quarter of that is the max distance a point may be away from locSantaCruz and still be in western hemisphere
dblQuarterEarth = dblHalfEarth / 2;
}
// Compute latitude from distance to north pole
dblLat = 90 - 180 * oMap.Distance(locNorthPole, oLocate) / dblHalfEarth;
d = oMap.Distance(oMap.GetLocation(dblLat, 0, 1), oLocate);
// convert latitude to radian
l = (dblLat / 180) * Math.PI;
// Compute Longitude from great circle distance
dblLon = 180 * Math.Acos((Math.Cos((d * 2 * Math.PI) / (2 * dblHalfEarth)) - Math.Sin(l) * Math.Sin(l)) / (Math.Cos(l) * Math.Cos(l))) / Math.PI;
//Correct longitude sign if located in western hemisphere
if ( oMap.Distance(locSantaCruz, oLocate) < dblQuarterEarth )
dblLon = -dblLon;
oPin = oMap.AddPushpin(oLocate, strAddress);
oPin.Highlight = true;
oPin.Symbol = 17;
oPin.BalloonState = MapPoint.GeoBalloonState.geoDisplayBalloon;
txtLat.Text = dblLat.ToString();
txtLong.Text = dblLon.ToString();
Thanks in advance for any help on this!!
At any rate, I have written a small C# app that takes a street address, city, state, and ZIP as input from a user. When the user clicks a button, the app goes out and finds the location in MapPoint, opens and plots the location on a map, and returns the Lat/Long of the location to the app.
If MapPoint finds an exact match for the location as input by the user, then it returns the Lat/Long values fine. However, if it doesn't find an exact match, I have it opening the 'ShowFindDialog' box. At this point, the user may click on an address in the returned list. What I'm having problems with at this point is having it return the Lat/Long of the selected address to my app.
Basically, I don't know how to get the results of what the user selected in the Dialog Box and do my Lat/Long calculation.
Below is the snippet of code that I'm using to calculate the Lat/Long ...
if ( MapPoint.GeoFindResultsQuality.geoFirstResultGood == oResults.ResultsQuality)
{
IEnumerator at = oResults.GetEnumerator();
if ( !at.MoveNext())
{
return null;
}
oLocate = (MapPoint.Location) at.Current;
}
else
{
//If no exact match found, open Dialog box
oMap.ShowFindDialog(strAddress, new MapPoint.GeoFindState(), (int)this.Handle, false);
return null;
}
oLocate.GoTo();
int x;
int y;
double dblLat;
double dblLon;
double l;
double d;
x = oMap.LocationToX(oLocate);
y = oMap.LocationToY(oLocate);
MapPoint.FindResults oContext;
oContext = oMap.ObjectsFromPoint( x, y);
MapPoint.Location obj;
if ( locNorthPole == null )
{
locNorthPole = oMap.GetLocation( 90, 0, 1 );
locSantaCruz = oMap.GetLocation( 0, -90, 1 );
// Compute distance between north and south poles == half earth circumference
dblHalfEarth = oMap.Distance( locNorthPole, oMap.GetLocation(-90, 0, 1) );
// Quarter of that is the max distance a point may be away from locSantaCruz and still be in western hemisphere
dblQuarterEarth = dblHalfEarth / 2;
}
// Compute latitude from distance to north pole
dblLat = 90 - 180 * oMap.Distance(locNorthPole, oLocate) / dblHalfEarth;
d = oMap.Distance(oMap.GetLocation(dblLat, 0, 1), oLocate);
// convert latitude to radian
l = (dblLat / 180) * Math.PI;
// Compute Longitude from great circle distance
dblLon = 180 * Math.Acos((Math.Cos((d * 2 * Math.PI) / (2 * dblHalfEarth)) - Math.Sin(l) * Math.Sin(l)) / (Math.Cos(l) * Math.Cos(l))) / Math.PI;
//Correct longitude sign if located in western hemisphere
if ( oMap.Distance(locSantaCruz, oLocate) < dblQuarterEarth )
dblLon = -dblLon;
oPin = oMap.AddPushpin(oLocate, strAddress);
oPin.Highlight = true;
oPin.Symbol = 17;
oPin.BalloonState = MapPoint.GeoBalloonState.geoDisplayBalloon;
txtLat.Text = dblLat.ToString();
txtLong.Text = dblLon.ToString();
Thanks in advance for any help on this!!