View Full Version : How to find nearest city?

Petr Brant
08-22-2002, 05:51 AM
Hi all,
I work with MS MapPoint 2002 under Delphi using TOleContainer. Everything works fine, but I have this problem: I have Lat and Long and want to search for nearest city. I need name of the city and name of the country, where it resides. I use this code:

Dist:= 1;
Loc:= self.GetLocation(X, Y);
Results:= Loc.FindNearby(Dist);
while &#40;Results.Count = 0&#41; and &#40;Dist < CMaxDist&#41; do
Results&#58;= Loc.FindNearby&#40;Dist&#41;;
Dist&#58;= Dist*2;
if Results.Count > 0 then //here I have all locations

But in Results are Hotels, Restaurants, etc. How to obtain nearest city name?

Thanks for all replies. Bye Petr

John Meyer
08-22-2002, 08:03 AM
One of the problems with the FindNearby method is results are limited to the CURRENTLY VISIBLE PlaceCategory objects (Like Restaurants, Airports etc..) So even if there is/was a way to get the city from the nearest "Place" the results could not be depended on.

A better approach might be what David is exploring (Also Delphi).


08-22-2002, 10:53 AM
Hi Petr, as said above I am doing the same sort of thing although I am searching for the nearest road from a point so I can get a postcode.

The Map.ObjectsFromPoint method:

mpResults &#58;= mpMap.ObjectsFromPoint&#40;mpMap.LocationToX&#40;mpLocatio n&#41;, mpMap.LocationToY&#40;mpLocation&#41;&#41;;

The above converts the Given location to a X,Y point on the Map it then searches for any Nearby Objects, roads, places of interest, towns etc..

John Meyer
08-23-2002, 01:49 PM
Ran accross this on MSDN

ZIP Code - City Finder Sample Code