MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Get country for lat & lon

This is a discussion on Get country for lat & lon within the MapPoint 2006/2009 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 ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-10-2005
Junior Member
White Belt
 
Join Date: Jul 2004
Posts: 2
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.

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 07-11-2005
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,046
Hi,

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 07-11-2005
calv1ns's Avatar
Member
Green Belt
 
Join Date: Mar 2005
Posts: 91
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:

http://www.mp2kmag.com/mappoint/disc...pic.asp?t=6193

My code in VB 6 looks like this:
<pre>
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)
map_centre.Goto
'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)
Else
Debug.Print "Street " + wk_street.City + " " + wk_street.Street + " " + Str(wk_obj.Location.Type)
End If
Next
myErr:
If Err.Number <> 0 Then
On Error GoTo 0
Debug.Print Err.Number, Err.Description
Err.Clear
wk_istat = -1
End If
set_location = wk_istat
End Function
</pre>
The two debug statements will print the results found which are held in the wk_results location object. For this example the results were:

8
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...
__________________
Calv1ns
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
country or state? Rick MapPoint Web Service and Virtual Earth 0 04-21-2006 02:59 PM
Country Codes cwrude MapPoint 2006/2009 Discussion 0 11-10-2004 09:47 AM
maps other country Anonymous MapPoint 2006/2009 Discussion 4 05-07-2004 09:05 AM
One country view only? Anonymous MapPoint 2006/2009 Discussion 1 04-18-2003 10:45 AM
Show only one country Anonymous MapPoint 2006/2009 Discussion 2 11-22-2002 01:56 PM


All times are GMT -5. The time now is 05:21 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5
MP2K Magazine
Visitor Map


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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51