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
Results 1 to 3 of 3

Get country for lat & lon

This is a discussion on Get country for lat & lon within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hello, I've been browsing around the msdn, but haven't found a solution for this, though it should be quite simple. ...

  1. #1
    zauber is offline Junior Member White Belt
    Join Date
    Jul 2004

    Get country for lat & lon

    Hello, I've been browsing around the msdn, but haven't found a solution for this, though it should be quite simple. Here's the problem:

    Working with the MappointControl in VisualBasic, I have a location object specified by a lat/lon coordinate pair. I would like to find out what Country that location is in.


  2. #2
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004

    Looks simple but it is not that simple
    If the position is not on a street then you dont get back a Location object. You get always a location object if you zoom to a large altitude, but then the Country is 'Default" which does not say mutch Also the FindNearBy seems to give only "Default" as country if it is an address

    Solution is check first if you get back a location object, if not then move the position around on the circumfence of a circle with given radius and same resolution on the circumfence. Break the loop if you find a Location object containing a StreetAddress. If not then increase radius, and so on.

  3. #3
    calv1ns's Avatar
    calv1ns is offline Member Green Belt
    Join Date
    Mar 2005

    Get Country - sorta easy

    This is very simliar to the private discussion you and I were having Wilfried. I hope this helps Zauber and sheds more light on my problem.

    For this example I use point Lat 49.2721 Long -123.0981 which using bare MapPoint 2004 is 1394 Station Street in Vancouver, BC, Canada.

    I used Wilfried's code posted at:


    My code in VB 6 looks like this:
    Public Function calc_addr(wk_lat As Double, wk_long As Double) As Integer
    Dim wk_istat As Integer
    Dim map_centre As MapPoint.Location
    Dim wk_results As MapPoint.FindResults
    Dim wk_street As StreetAddress
    ' do not comment the next line in a production system
    ' On Error GoTo myErr:
    wk_istat = 1
    'lat / long normally passed into the function as wk_lat and wk_long but hard coded for the example
    Set map_centre = myobj.GetLocation(49.27209, -123.098132, 0)
    'wk_x and wk_y are NOT lat / long but pixel coordinates on the screen
    wk_x = myobj.LocationToX(map_centre)
    wk_y = myobj.LocationToY(map_centre)
    Set wk_results = myobj.ObjectsFromPoint(wk_x, wk_y)
    Debug.Print wk_results.Count
    For Each wk_obj In wk_results
    Set wk_street = wk_obj.Location.StreetAddress
    If wk_street Is Nothing Then
    Debug.Print "Result " + wk_obj.Location.Name + " " + Str(wk_obj.Location.Type)
    Debug.Print "Street " + wk_street.City + " " + wk_street.Street + " " + Str(wk_obj.Location.Type)
    End If
    If Err.Number <> 0 Then
    On Error GoTo 0
    Debug.Print Err.Number, Err.Description
    wk_istat = -1
    End If
    set_location = wk_istat
    End Function
    The two debug statements will print the results found which are held in the wk_results location object. For this example the results were:

    Street Vancouver 1394 Station St -1
    Street Vancouver 297 Northern St -1
    Street Vancouver Terminal Ave -1
    Result Coast Mountains -1
    Result Pacific (GMT - -1
    Result Vancouver 8
    Result British Columbia 18
    Result Canada 19

    For zauber the solution is easy. Loop through your results looking for a location with .location.type = 19 and use the .location.name

    For pure reverse goecoding of street address the solution is less obvious. Note the first three results had valid streetaddress and the first five had .location.type as -1. If there were a pushpin dataset on the map those records at this location would also be returned as type -1. There should be an easy way to determine the source of the returned results. What this is I have no idea. Any one with ideas please let us know.

    Note: Look in MP Help for GeoShowDataBy values

    GeoShowDataBy values describe the geographical unit by which data is displayed on the map.

    Applies to
    Methods: DisplayDataMap
    Properties: ShowDataBy, Type (Location)

    This is where you determine 19 is a country, 8 is a city, 18 is a region, etc...

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. country or state?
    By Rick in forum Bing Maps and MapPoint Web Service
    Replies: 0
    Last Post: 04-21-2006, 02:59 PM
  2. Country Codes
    By cwrude in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 11-10-2004, 09:47 AM
  3. maps other country
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 4
    Last Post: 05-07-2004, 09:05 AM
  4. One country view only?
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 04-18-2003, 10:45 AM
  5. Show only one country
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 11-22-2002, 01:56 PM

Tags for this Thread

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36