spacer1
spacer2 1_1 1_2
2_1
 Subscribe
 The MP2K Update!
 
 
 
 Magazine
Front Cover
What's New
Articles
News
Sample Data
Gallery
Advertise
About
 Features
MapPoint 2011
Press Releases
MapPoint Forums
Companies
Link to MP2Kmag
Wish List
MapPoint Trial
Authors
 Earlier Content
Past News Items
Past What's New Announcements
 Sponsors
 Order

MapPoint 2011

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
SVG Tutorials
MapPoint

Map Visitors

  ARTICLES  


Determing the Time Zone in MapPoint

Leon Schell shares a method for determining the time zone by accessing hidden POI information

A question that gets asked every once in a while is whether it's possible to display time zones in MapPoint. Using and experimenting with articles from John Washenberger and Gilles Kohl I have come up with the following solution.

One way to get to the time zone information is to loop through POI's in a way described by John. Basically, you first determine the area you want to examine and then loop through that area using a longitudinal (east to west) loop nested within a latitudinal (south to north) loop. In the code example below, I will try to get the time zone information for Portugal, Spain and France, using latitudes ranging from 36 to 44 degrees N and longitudes ranging from 10 degrees W to 4 degrees E. Since looping through all POI's can be time consuming, I decided to include only major airports - I think it is fair to presume that every country or state you want to map at least has one major airport.

In my case I have used: Windows XP Pro with MapPoint 2004 Europe and Excel 2003.

To try this yourself, open a new Excel workbook, add a command button to the sheet and double click it. Set a reference to 'Microsoft MapPoint 11.0 Object Library' via Tools | References in the code window. Then, in the CommandButton1_Click() sub, paste the following code together with the CalcPos sub and Arccos function that you can find in Gilles' article mentioned above.

  Dim objApp As Object
Set objApp = CreateObject("MapPoint.Application")
objApp.Visible = True
objApp.UserControl = True
objApp.NewMap
objApp.ActiveMap.MapStyle = geoMapStyleRoad
objApp.PaneState = geoPaneNone

Dim objMap As MapPoint.Map
Set objMap = objApp.ActiveMap
Dim objSymbol As MapPoint.Symbol
Dim objPlaceCat As MapPoint.PlaceCategory
Dim objFindResults As MapPoint.FindResults
Dim objLocLatLon As MapPoint.Location
Dim objLocFindResults As MapPoint.Location
Dim objPin As MapPoint.Pushpin
Dim objPinOrLoc As Object
Dim objResults As MapPoint.FindResults
Dim objResult As Object

Dim lngCount As Long ' /// POI counter
Dim lngSheetRow As Long ' /// Row in sheet
Dim iLat As Integer ' /// To loop through Lats
Dim iLon As Integer ' /// To loop through Lons
Dim dblLat As Double ' /// Latitude of POI
Dim dblLon As Double ' /// Longitude of POI
Dim strCategory As String ' /// POI Category
Dim strTimeZone As String ' /// Time zone of POI
Dim strCountry As String ' /// Country of POI

' /// Select major airports only
strCategory = "Airports - Major"
For Each objPlaceCat In objMap.PlaceCategories
If objPlaceCat.Name = strCategory Then
objPlaceCat.Visible = True
Else
objPlaceCat.Visible = False
End If
Next

lngSheetRow = 1
For iLat = 36 To 44
Range("Sheet1!A1").Select
ActiveCell.Value = iLat
For iLon = -10 To 4
lngCount = 0
' /// Move to current lat/lon
Set objLocLatLon = objMap.GetLocation(iLat, iLon)
' /// Get POIs within 80 km radius
Set objFindResults = objLocLatLon.FindNearby(80)

' /// Update sheet to show where we are
Range("Sheet1!B1").Select
ActiveCell.Value = iLon
Range("Sheet1!C1").Select
ActiveCell.Value = 0
Range("Sheet1!D1").Select
ActiveCell.Value = objFindResults.Count

' /// Process all POIs
For Each objPinOrLoc In objFindResults
If TypeOf objPinOrLoc Is MapPoint.Location Then
dblLat = 0
dblLon = 0
lngSheetRow = lngSheetRow + 1
' /// Calculate the POIs Lat/Lon
CalcPos objMap, objPinOrLoc, dblLat, dblLon
' /// Add a record to the sheet
Range("Sheet1!A" & Trim(CStr(lngSheetRow))).Select
ActiveCell.Value = dblLon
Range("Sheet1!B" & Trim(CStr(lngSheetRow))).Select
ActiveCell.Value = dblLat
Range("Sheet1!C" & Trim(CStr(lngSheetRow))).Select
ActiveCell.Value = objPinOrLoc.Name
objPinOrLoc.Location.Goto
objMap.Altitude = 12
Set objResults = objMap.ObjectsFromPoint( _
objMap.LocationToX( _
objMap.GetLocation(dblLat, dblLon)), _
objMap.LocationToY( _
objMap.GetLocation(dblLat, dblLon)))
strTimeZone = vbNullString
strCountry = vbNullString
For Each objResult In objResults
' This error catching shouldn't be necessary in my view
' but not all objResult objects seem to have a
' .Type property.
' Let's just skip them
On Error Resume Next
If objResult.Type = geoShowByCountry Then
If Err.Number = 0 Then
strCountry = objResult.Name
Range("Sheet1!D" & Trim(CStr(lngSheetRow))).Select
ActiveCell.Value = strCountry
Else
Err.Clear
End If
End If
If objResult.Type = -1 Then
If Err.Number = 0 Then
If Left(objResult.Name, 3) = "GMT" Then
strTimeZone = objResult.Name
Range("Sheet1!E" & Trim(CStr(lngSheetRow))).Select
ActiveCell.Value = strTimeZone
End If
Else
Err.Clear
End If
End If
Next
End If
' /// Update sheet to show where we are
lngCount = lngCount + 1
Range("Sheet1!C1").Select
ActiveCell.Value = lngCount
DoEvents
Next
Next
Next

objMap.DataSets.ZoomTo
objMap.Saved = True

Set objFindResults = Nothing
Set objLocLatLon = Nothing
Set objLocFindResults = Nothing
Set objPin = Nothing
Set objResults = Nothing
Set objSymbol = Nothing
Set objMap = Nothing
Set objApp = Nothing

After clicking the command button, the program will start MapPoint and fill the Excel sheet with the airports found, their longitude and latitude, the country and time zone they belong to. In the way the program works, many airports will be found more than once but that doesn't matter much for our purpose.

After the program has finished, in Excel, delete row 1 which contains the user interface to show the progress - we won't need it any longer and it will interfere with MapPoint wizard we are about to use. But first save the sheet somewhere, for example on the desktop. Now switch to MapPoint and start the Create Territories Wizard by selecting Data | Territories... from the menu. Select 'Create from your own set of data' and click 'Next'. Select 'Import your source file', click 'Next'. Select the Excel sheet you just saved and click 'Open'. Select 'Sheet1' when asked to 'Choose the sheet or range you want to map'. Click 'Next'. Now, using the European version of MapPoint, you have to select '<Multi/Other>' from the Country/Region drop down box. Deselect 'First row contains column headings'. From the 'Data type' drop down box select 'Country/Region' in the 4th column (F4) and 'Territory' under F5. Leave the first three columns to '<Skip Column>'. Finally, click finish. MapPoint will now show the time zone information for Portugal, Spain and France.

Gotchas:

- As far as I know, the time zone information will not take into account summer time changes. For example, I know that in the U.S. some states change to daylight saving time while others (or even parts of others) do not. I haven't tested it but I imagine the info retrieved through the procedure above will be valid during winter time only.

- As the code was used with the European version of MapPoint, U.S. users should change the lines

  ' /// Get POIs within 80 km radius
Set objFindResults = objLocLatLon.FindNearby(80)
to
  ' /// Get POIs within 50 miles radius
Set objFindResults = objLocLatLon.FindNearby(50)

- For obvious reasons, this method only works for those countries and states that are covered in MapPoint and at least have major airports POI information.



Discuss this story in the forum.

Author: Leon Schell
Email: lschell(AT)web.de
Leon is an IT project manager for a Dutch airline company. His interests are programming, travelling (by plane and by car), Pocket PCs, GPS navigating, new technologies and finding new utilizations for existing (Microsoft) software.



Google
 
MP2Kmag Internet


 Recent Discussion
-MP 2011 Silent Install with Key AND Activation?
-Convert .GmL to a spatial data type
-bingmaps: Spouse run interference on an Indianapolis road trip for Super Bowl? Get the best view on Bing Maps. BYO beer & chips*http://t.co/hkZlFnJ4
-MAP POINT Route Planning
-MapPoint Routes: Multiple start points, one stop point.
-Export Territories - plot them on google maps or bing
-bingmaps: Check out this blog and interview to learn more about LifeLens and Bing Maps http://t.co/mlNHyKdW
-Can't make working OLAP add-in
-Importing data from Canada?
-MapPoint North America 2011 - UK Postcodes?
-Seeking Church Demographic info for MP2011
-Exporting Pushpin Counts in a radius
-bingmaps: RT @bing: Congrats to the Imagine Cup Grant Winners, esp. OaSys and LifeLens using @Bing maps! http://t.co/Fha9Cf0V
-Store Distance Calculations
-Modify maps
-Win7x64SP1 clobbers MapPoint 2010....
-bingmaps: RT @ChrisPendleton: New Bing Maps Features Help You Feel Spatial…
-Hope it doenst soudn TOO much like Im a Noob.. BUT...
-Capture click events from MapPoint to my Winforms app?
-bingmaps: @natelawrence Thanks for the feedback...check out our*Forum for technical assistance:*http://t.co/WDAjNJCD
-bingmaps: @Jordanaous*We're glad you're enjoying Streetside...thanks for using Bing Maps!
-bingmaps: @Goodlett*A beautiful partnership, indeed.
-bingmaps: @urbanmapping Love the fascinating questions you guys are asking, and the important information you provide. Keep it up!
-bingmaps: @beeinthehive*Happy to help! Thanks for using Bing Maps!
-bingmaps: @Geocrusader80* Isn't the imagery amazing? Glad you're a fan!
 Resources
Browse GIS books and periodicals
Find a MapPoint Partner or Consultant
Real Estate Columbia Custom Home


Want Your Site To Appear Here?

   © 1999-2009 MP2K. Questions and comments to: website@mp2kmag.com
  Microsoft and MapPoint 2002/2004/2006/2009 are either trademarks or registered trademarks of Microsoft.



• Buy Your Car Used Cars UK, Car Lease and Contract Hire