View Single Post

  #7 (permalink)  
Old 08-20-2002
David David is offline
Junior Member
Yellow Belt
 
Join Date: Aug 2002
Posts: 13
This is'nt "exactly" what tried, but it was something along these lines:

mpLocation is the location from which I want to find the nearest Street, lets say for example the postcode for mpLocation is 'RG6 3XA'.

Note mpMap is a Public Object of TMap (MapPoint Map).

Code:
//mpLocation is the location we are trying to reverse look-up, the result/output
//(TLocation) is a custom object containing address information: street, town etc.
function TMapPointThd.FindNearestStreet(mpLocation : Location) : TLocation;
var
  mpResults  : FindResults;
  iResult    : Integer;
  oleCount   : oleVariant;
  oleResult  : oleVariant;

begin

  //Not sure exactly what this does but im told its nessessary??
  mpLocation.GoTo_;

  //Convert the given locaton to X and Y co-ord's on the map.
  mpResults := mpMap.ObjectsFromPoint(mpMap.LocationToX(mpLocation),mpMap.LocationToY(mpLocation));

  //Use an oleVariant object to store the number of results.
  oleCount := mpResults.Count;

  //do we have any results?
  if (oleCount > 0) then
  begin
    //loop through all the results.
    for iResult := 1 to oleCount do
    begin
      //Another ole variant is required to read the results so we convert the
      //integer iResults to an oleVariant type.
      oleResult := iResult;

      //Make sure the result is not nil.
      if (mpResults.Item[oleResult] <> Nil) then
      begin
        //Look up the street name..
        Result.Street := Location(mpResults.Item[oleResult]).StreetAddress.Street;
      end;
    end;
  end;
end;
Reply With Quote