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 2 of 2

Automatically Publishing MapPoint Maps to Mobile Devices

This is a discussion on Automatically Publishing MapPoint Maps to Mobile Devices within the MP2K Magazine Articles forums, part of the Map Forums category; In this article, Eric Frost shows how maps created with Microsoft MapPoint 2010 can be automatically published to the web ...

  1. #1
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4

    Automatically Publishing MapPoint Maps to Mobile Devices

    In this article, Eric Frost shows how maps created with Microsoft MapPoint 2010 can be automatically published to the web and displayed on mobile devices.

    This is a fairly simple Excel macro which automatically runs when the macro workbook is opened and creates maps and copies the graphics via FTP to a web server. The images are sized to 800 x 480 which happens to be the dimensions of my HTC EVO phone. If publishing to another device such as an iPad (1024 by 768 ) you could modify the dimensions in the Excel macro.



    This project consists of four files. One macro-enabled Excel workbook (.xlsm), one normal data workbook (.xlsx), and two MapPoint .ptm files. For whatever reason, MapPoint does not recognize nor is able to import directly from .xlsm files, thus the need for a separate Excel data workbook.

    For this exercise, the data being mapped is random data generated for U.S. states and all the counties in Illinois - two separate maps. Take a look at the maps here -- http://www.mp2kmag.com/htc_evo/. These are the maps that are automatically created and published by the macro contained in the Mobile Example Macro.xlsm workbook.

    The data is created in the Mobile Example Random Data.xlsx workbook using the RANDBETWEEN function. The first thing the macro does it open up this workbook and update the random data values, then saves the workbook.

    Code:
        'open rand data workbook and save
        Workbooks.Open Filename:=ThisWorkbook.Path & "\Mobile Example Random Data.xlsx"
        Workbooks("Mobile Example Random Data.xlsx").Activate
        Range("StateData").Calculate
        Range("CountyData").Calculate
        
        ActiveWorkbook.Save
        ActiveWorkbook.Close
    For real-world data, you could imagine this data might be sales coming from a corporate database, and xml feed with daily updated weather data (XML data feeds - Current Conditions - NOAA's National Weather Service), economic data scraped from the web e.g. Unemployment rates - Unemployment rates by state from CNNMoney), or perhaps manually prepared.

    The two MapPoint .ptm files DatabyCounty.ptm and DatabyState.ptm each have linked datasets pointing to the data workbook. Once the randomly generated data has been updated in the previous step, the next thing the macro needs to do is open up both .ptm files and update the linked dataset using the .UpdateLink method.

    Code:
        'open ptm files, update linked data, and save
        Dim MPApp As MapPoint.Application
        Dim objMap As MapPoint.Map
        Set MPApp = CreateObject("MapPoint.Application")
    
        MPApp.Visible = True
        Set objMap = MPApp.ActiveMap
        MPApp.OpenMap (ThisWorkbook.Path & "\DatabyCounty.ptm")
        objMap.DataSets(2).UpdateLink
        Dim objSW As MapPoint.SavedWebPage
        Set objSW = objMap.SavedWebPages.Add("DatabyCounty", _
          objMap.Location, "DatabyCounty", _
          True, False, True, 800, 480, False, True, False, True)
        objSW.Save
        objSW.AutoResave = True
        objMap.Save
        objMap.SaveAs "DatabyCounty", geoFormatHTMLMap, True
        
        objMap.Saved = True
        
        MPApp.OpenMap (ThisWorkbook.Path & "\DatabyState.ptm")
        objMap.DataSets(2).UpdateLink
        Set objSW = objMap.SavedWebPages.Add("DatabyState", _
          objMap.Location, "DatabyState", _
          True, False, True, 800, 480, False, True, False, True)
        objSW.Save
        objSW.AutoResave = True
        objMap.Save
        objMap.SaveAs "DatabyState", geoFormatHTMLMap, True
        
        objMap.Saved = True
        
        MPApp.Quit
        Set MPApp = Nothing
    You can see in the code above, the program is also creating a saved web page for each map. This is one method for getting a map image file of the MapPoint map. It may not be the most elegant way as a bunch of extra files and folders are created that we are not going to use, but it's simple and it works.

    You can see in the code above where the image dimensions are set. This helps it display properly without being grainy or requiring the mobile user to have to zoom in on the image.

    The last thing to be done is upload the images. This is accomplished by creating a couple of script files which are run in a command shell. Again, not the most elegant way to accomplish FTP within Excel VBA, but it's simple and it works.

    Code:
        'upload images
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set a = fs.CreateTextFile("c:\temp\script.dat", True)
        a.writeline "user" 'put in your ftp user name
        a.writeline "pass" 'and password
        a.writeline "cd public_html"
        a.writeline "cd htc_evo"
        a.writeline "bin"
        a.writeline "put " & Chr(34) & "C:\Work\2011_01_04_HTC_EVO\Data by County_files\image_map.gif" & Chr(34)
        a.writeline "rename image_map.gif county_map.gif"
        a.writeline "put " & Chr(34) & "C:\Work\2011_01_04_HTC_EVO\Data by State_files\image_map.gif" & Chr(34)
        a.writeline "rename image_map.gif state_map.gif"
        a.writeline "quit"
        a.Close
    
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set a = fs.CreateTextFile("c:\temp\upload.bat", True)
        a.writeline "ftp -i -s:c:\temp\script.dat www.example.com"
        a.Close
    
        dRetVal = Shell("C:\temp\upload.bat ", 0)
    I welcome comments, suggestions, extensions on the above solution for automatically publishing MapPoint maps to the web formatted for mobile devices. I am also eager to hear what uses you can put this to (e.g. sending a list of stops to drivers, sending updated leads in a particular city to a salesforce, etc.) and would also be glad to help implement something for your organization.

    All four files referenced above are zipped up and available for download here. Note that this will not work right out of the box as I have removed my ftp user name and password from the script, but if you have a web server and ftp site it would be trivial to put those in.

    Have Fun and Happy Mapping!

    Eric Frost
    Last edited by Eric Frost; 01-05-2011 at 08:16 AM.
    ~ Order MapPoint MapPoint 2013 Here and Get Free Access to the MapForums Downloads ~
    ~~
    ~ Upgrade to Get Access to the MapForums Downloads ~

  2. #2
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4

    Re: Automatically Publishing MapPoint Maps to Mobile Devices

    By the way, here are some live links to the maps.

    As I periodically open the macro, these map images are recreated and changed!





    Eric
    ~ Order MapPoint MapPoint 2013 Here and Get Free Access to the MapForums Downloads ~
    ~~
    ~ Upgrade to Get Access to the MapForums Downloads ~

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. The Bing Maps AJAX Control on Mobile Devices
    By Johannes Kebeck's Blog in forum Bing Maps Blogs & Tweets
    Replies: 0
    Last Post: 06-29-2010, 01:01 PM
  2. Replies: 0
    Last Post: 02-03-2010, 05:31 PM
  3. Using Mappoint for Publishing a Short Report
    By maxvonprofitman in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 10-05-2007, 07:51 AM
  4. Opinions for Publishing BI MapPoint Map and Feeding Criteria to it
    By abilbrey in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 04-25-2007, 02:47 PM
  5. Do maps automatically scale?
    By jvolpe in forum Bing Maps and MapPoint Web Service
    Replies: 0
    Last Post: 10-20-2006, 04:22 PM

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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123