Community of VE/MapPoint Users and Developers
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 ...
| |||||||
| Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| Get country for lat & lon 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! |
| |||
|
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 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.
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| ||||
| 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 - 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 |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| 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 |