Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

 Subscribe to receive our newsletter. Subscribe Unsubscribe

## How to retrieve nearest city from longitudes and latitud

This is a discussion on How to retrieve nearest city from longitudes and latitud within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hello I have an application over Visual C++ and i need to find the nearest city to an geografic point ...

1. Junior Member White Belt
Join Date
Mar 2006
Posts
3

## How to retrieve nearest city from longitudes and latitud

Hello

I have an application over Visual C++ and i need to find the nearest city to an geografic point (latitud , longuitud ) . I have the following code but is crashing in the GetStreetAddress() function. Does anyone have any idea ??

Code:
```CLocation loc,streetLoc;
CFindResults streetResults;
CStreetAddress callejero;

loc = mapa.GetLocation&#40;lat, lon, 0&#41;;
loc.GoTo&#40;&#41;;

streetResults = mapa.ObjectsFromPoint&#40;mapa.LocationToX&#40;loc&#41;, mapa.LocationToY&#40;loc&#41;&#41;;

int numResult=streetResults.GetCount&#40;&#41;;
int i=1;
while &#40; i <=numResult&#41;
&#123;

VARIANT idx;
VariantInit&#40; &idx &#41;;
V_VT&#40;&idx&#41; = VT_I4;
V_I4&#40;&idx&#41; = 1;

streetLoc=streetResults.GetItem&#40; &idx &#41;;

szLocalidad=streetLoc.GetLocation&#40;&#41;.GetName&#40;&#41;;

callejero=streetLoc.GetStreetAddress&#40;&#41;;

i++;
&#125;```

2. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
Hi,

"Crashing" does not mean muthc. Put you code into an exeption blockand reply with the exact error you have. This way we can help more.

3. Junior Member White Belt
Join Date
Mar 2006
Posts
3
I have done , my excepction is produced in the line
Code:
`callejero=streetLoc.GetStreetAddress&#40;&#41;;`
and gives the following exception "menber not found".

4. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
Hi,

I dont think there is a GetStreetAddress method in a Location object. I think what you are looking for is the StreetAddress property, so:

Code:
`callejero = streetLoc.StreetAddress;`

5. Junior Member White Belt
Join Date
May 2011
Posts
1

## Re: How to retrieve nearest city from longitudes and latitud

Hello ,

I need java code to find nearest city for a given latitude and longitude. Or is there any class in java to find nearest city using GMT offset? Please help me. Thank you.
Last edited by sush; 05-16-2011 at 02:59 AM.

#### Thread Information

##### Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

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