Solved

using web browser with BING

Posted on 2016-11-07
40
80 Views
Last Modified: 2016-11-20
I am developing a database where I want to see, on BING, the selected place. I am using the webbrowser activeX and it is working.
Now I need to populate the picture with some text and pushpin. so I came to the following page:

http://www.bing.com/api/maps/sdk/mapcontrol/isdk#pushpinLabels+HTML
and got the HTML source code (they also have the java code)
and using the excellent ste5an suggestion I pasted the code ont a string (strMap) as follows:

Private Sub btnGo_Click()

  Set m_WebBrowser = ctlWebBrowser.Object
  m_WebBrowser.Navigate "about:blank"
  ' m_WebBrowser.Document.Write "<h1>Test</h1>"
  
  
  Dim strMap As String
  
  strMap = "<!DOCTYPE html>" & vbCrLf
strMap = strMap & " < head > " & vbCrLf
strMap = strMap & "        <title>pushpinLabelsHTML</title>" & vbCrLf
strMap = strMap & "        <meta http-equiv='Content-Type' content='text/html; charset=utf-8’/>" & vbCrLf
strMap = strMap & "    </head>" & vbCrLf
strMap = strMap & " < body > " & vbCrLf
strMap = strMap & "       <div id='printoutPanel'></div>" & vbCrLf
strMap = strMap & vbCrLf
strMap = strMap & "        <div id='myMap' style='width: 100vw; height: 100vh;'></div>" & vbCrLf
strMap = strMap & "        <script type='text/javascript’>" & vbCrLf
strMap = strMap & "           function loadMapScenario() {" & vbCrLf
strMap = strMap & "                var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {" & vbCrLf
strMap = strMap & "                    credentials: 'Your Bing Maps Key’” & vbCrLf"
strMap = strMap & "                });" & vbCrLf
strMap = strMap & "                var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), { text: 'A', title: 'Title', subTitle: 'Subtitle' });" & vbCrLf
strMap = strMap & "                map.entities.push(pushpin);" & vbCrLf
strMap = strMap & vbCrLf
strMap = strMap & "            }" & vbCrLf
strMap = strMap & "        </script>" & vbCrLf
strMap = strMap & "        <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?branch=release&callback=loadMapScenario' async defer></script>" & vbCrLf
strMap = strMap & "    </body>" & vbCrLf
strMap = strMap & "</html>"

  MsgBox strMap
  Debug.Print strMap
  m_WebBrowser.Document.Write strMap
    

End Sub

Open in new window



but now, the only thing that shows is

sshot
however the original code from Ste5an works perfect

what shall I do? can I use the Javascript version that is more compact and readable?

thanks for any help
0
Comment
Question by:jirdeaid
  • 17
  • 17
  • 4
  • +1
40 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
too many minor errors, particularly at:

  • < head >
  • charset=utf-8?>
  • < body >
  • <script type='text/javascript’"
  • credentials: 'Your Bing Maps Key’” & vbCrLf"

I think you mixed up with Chinese input characters of ' and " ?

hence try this instead:
Dim strMap As String
  
  strMap = "<!DOCTYPE html>" & vbCrLf
strMap = strMap & " <head> " & vbCrLf
strMap = strMap & "        <title>pushpinLabelsHTML</title>" & vbCrLf
strMap = strMap & "        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>" & vbCrLf
strMap = strMap & "    </head>" & vbCrLf
strMap = strMap & " <body> " & vbCrLf
strMap = strMap & "       <div id='printoutPanel'></div>" & vbCrLf
strMap = strMap & vbCrLf
strMap = strMap & "        <div id='myMap' style='width: 100vw; height: 100vh;'></div>" & vbCrLf
strMap = strMap & "        <script type='text/javascript'>" & vbCrLf
strMap = strMap & "           function loadMapScenario() {" & vbCrLf
strMap = strMap & "                var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {" & vbCrLf
strMap = strMap & "                    credentials: 'Your Bing Maps Key'" & vbCrLf
strMap = strMap & "                });" & vbCrLf
strMap = strMap & "                var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), { text: 'A', title: 'Title', subTitle: 'Subtitle' });" & vbCrLf
strMap = strMap & "                map.entities.push(pushpin);" & vbCrLf
strMap = strMap & vbCrLf
strMap = strMap & "            }" & vbCrLf
strMap = strMap & "        </script>" & vbCrLf
strMap = strMap & "        <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?branch=release&callback=loadMapScenario' async defer></script>" & vbCrLf
strMap = strMap & "    </body>" & vbCrLf
strMap = strMap & "</html>"

Open in new window

0
 

Author Comment

by:jirdeaid
Comment Utility
mmmhh thanks, but now I am getting a totally white page...

I must be wrongdoing some other stuff.. Can I use the JAVASCRIPT instead?

please check the current string:

sshot 1
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
try to see if this works for you?
Private Sub btnGo_Click()
    Set m_WebBrowser = ctlWebBrowser
    Dim strMap As String
    
    m_WebBrowser.Navigate "about:blank"
    Do Until m_WebBrowser.ReadyState = 4
        DoEvents
    Loop
      
    strMap = "<!DOCTYPE html>" & vbCrLf
    strMap = strMap & "<html>" & vbCrLf
    strMap = strMap & " <head> " & vbCrLf
    strMap = strMap & "        <title>pushpinLabelsHTML</title>" & vbCrLf
    strMap = strMap & "        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>" & vbCrLf
    strMap = strMap & "    </head>" & vbCrLf
    strMap = strMap & " <body> " & vbCrLf
    strMap = strMap & "       <div id='printoutPanel'></div>" & vbCrLf
    strMap = strMap & vbCrLf
    strMap = strMap & "        <div id='myMap' style='width: 100vw; height: 100vh;'></div>" & vbCrLf
    strMap = strMap & "        <script type='text/javascript'>" & vbCrLf
    strMap = strMap & "           function loadMapScenario() {" & vbCrLf
    strMap = strMap & "                var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {" & vbCrLf
    strMap = strMap & "                    credentials: 'Your Bing Maps Key'" & vbCrLf
    strMap = strMap & "                });" & vbCrLf
    strMap = strMap & "                var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), { text: 'A', title: 'Title', subTitle: 'Subtitle' });" & vbCrLf
    strMap = strMap & "                map.entities.push(pushpin);" & vbCrLf
    strMap = strMap & vbCrLf
    strMap = strMap & "            }" & vbCrLf
    strMap = strMap & "        </script>" & vbCrLf
    strMap = strMap & "        <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?branch=release&callback=loadMapScenario' async defer></script>" & vbCrLf
    strMap = strMap & "    </body>" & vbCrLf
    strMap = strMap & "</html>"
    
    'MsgBox strMap
    'Debug.Print strMap
    TmpFile = Application.CurrentProject.Path & "\test.html"
    Call WriteFile(TmpFile, strMap)
    
    m_WebBrowser.ControlSource = "=""" & TmpFile & """"
    m_WebBrowser.Navigate Replace("file:///" & TmpFile, "\", "/")
    
End Sub

Sub WriteFile(ByVal FilePath As String, ByVal Content As String)
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    Dim file
    Set file = fso.CreateTextFile(FilePath, True, True)
    file.Write Content
    
    file.Close
    Set file = Nothing
    Set fso = Nothing
End Sub

Open in new window

0
 

Author Comment

by:jirdeaid
Comment Utility
well ... not yet - there is a compiler error

the error
I do not know which "dim as" I should use... I have browsed a bit but without any conclusion.

I am sending in the database as well: it is extremely simple: just a button and the webbrowser control, so you may check..

thanks for any help
joao
TESTES-WEB-BROWSWER.accdb
0
 

Author Comment

by:jirdeaid
Comment Utility
Hi..

am I left alone?
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
You will have a hard time with this, as the web controls (both the Active-X and the native from the band) uses Internet Explorer, and this doesn't allow scripts being run from local files just like that. Such a file must be marked to run with low security which either requires user intervention
or admin rights, neither of which are feasible in real life for a dynamically created file. Of course, if the file is static (not created by your application), you can set the security and are free to go.

Your best option is most likely to have the file saved on a (local) web server and then open it with some parameters.

I modified your code to demonstrate the behaviour - se in-line notes:
Option Compare Database
Option Explicit

Private Sub btnGo_Click()
   
    Dim WebBrowser  As Object
    Dim strMap      As String
    Dim FileName    As String
    
    Set WebBrowser = Me!ctlWebBrowser
    
    strMap = "<!DOCTYPE html>" & vbCrLf
    strMap = strMap & "<!-- saved from url=(0014)about:internet -->" & vbCrLf
    strMap = strMap & "<html>" & vbCrLf
    strMap = strMap & "<head> " & vbCrLf
    strMap = strMap & "    <title>pushpinLabelsHTML</title>" & vbCrLf
    strMap = strMap & "    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>" & vbCrLf
    strMap = strMap & "</head>" & vbCrLf
    strMap = strMap & "<script type='text/javascript'>" & vbCrLf
    strMap = strMap & "    function loadMapScenario() {" & vbCrLf
    strMap = strMap & "        var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {" & vbCrLf
    strMap = strMap & "            credentials: 'Your Bing Maps Key'" & vbCrLf
    strMap = strMap & "            });" & vbCrLf
    strMap = strMap & "        var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), {" & vbCrLf
    strMap = strMap & "            text: 'A', " & vbCrLf
    strMap = strMap & "            title: 'Title', " & vbCrLf
    strMap = strMap & "            subTitle: 'Subtitle'" & vbCrLf
    strMap = strMap & "            });" & vbCrLf
    strMap = strMap & "        map.entities.push(pushpin);" & vbCrLf
    strMap = strMap & "    }" & vbCrLf
    strMap = strMap & "</script>" & vbCrLf
    strMap = strMap & "<body> " & vbCrLf
    strMap = strMap & "    <div id='printoutPanel'>" & vbCrLf
    strMap = strMap & "        <div id='myMap' style='width: 100vw; height: 100vh;'>" & vbCrLf
    strMap = strMap & "            <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?branch=release&callback=loadMapScenario' async defer></script>" & vbCrLf
    strMap = strMap & "        </div>" & vbCrLf
    strMap = strMap & "    </div>" & vbCrLf
    strMap = strMap & "</body>" & vbCrLf
    strMap = strMap & "</html>"
    
'    MsgBox strMap
'    Debug.Print strMap
    FileName = Application.CurrentProject.Path & "\mappage.html"
    Call WriteFile(FileName, strMap)
    
    Stop
    '
    ' Apply "low" integrity level so the file is forced to run in the Internet zone when IE opens it.
    '
    ' 1. use Shell with admin rights to call:
    '   icacls <FileName> /setintegritylevel low
    '
    ' Or:
    '
    ' 2. Open the file in Internet Explorer.
    ' Save page as file. Use the same file path and name.
    '
    ' Then continue.
    
    WebBrowser.Navigate Replace("file:///" & FileName, "\", "/")

End Sub

Sub WriteFile(ByVal FilePath As String, ByVal Content As String)

    Const fsoForWriting = 2
    
    Dim objFSO As Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    ' Open the file.
    Dim objTextStream As Object
    Set objTextStream = objFSO.OpenTextFile(FilePath, fsoForWriting, True)
    
    ' Write the contents to the text file
    objTextStream.WriteLine Content
    
    ' Close the file and clean up.
    objTextStream.Close
    Set objTextStream = Nothing
    Set objFSO = Nothing

End Sub

Open in new window

/gustav
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
@jirdeaid,
I was away for some time...

For the error: Variable not defined, you need to define that variable before you referring to it.

add:
Dim TmpFile As String

Open in new window

before that line of code

OR you can simply turn off (remark): Option Explicit from your codes
0
 

Author Comment

by:jirdeaid
Comment Utility
Hi -

Oh boy they really are bad news. I am a rookie on internet programming. I do own a site where I could put the file and, from microsoft examples, a Javascript (which they provide) would be much more compact and readable. I guess that I need to find a manner to store there the files.

I realize that this is starting to be out of the scope of the current question and my problem remains.

A quick question from reading your code: it looks that is complete and I can actually use it, just replacing the  [strMap] with whatever "program" I need, be it javascript or HTML.

Is this right? Or do I need to actually store the strMap in my site and load from there?

thanks for the help
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
strMap is the full content of the html file no matter where it is stored.

As I understand it, you could run one of the tiny "personal" web servers, save the file to its file store (where you would have direct access), and then load the file from the web server (at address localhost or 127.0.0.1). That would be easier and faster than uploading via FTP to a remote server.

/gustav
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
@jirdeaid
Or do I need to actually store the strMap in my site and load from there?
Your original code didn't store the content into physical file but I think it would be easier if we store it somewhere and load it via the web browser control.
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
That is correct. You used the other control and passed it strMap:

  m_WebBrowser.Document.Write strMap

but, sadly, that doesn't make a difference; the control still refuses to run the script as - even when not written to a file - is regarded as "local".

/gustav
0
 

Author Comment

by:jirdeaid
Comment Utility
Hi Gustav and Ryan -


really - I do appreciate your help pointing me in the right direction. Still, I do need to better understand and implement a solution.

I reckon that, accordingly to

"As I understand it, you could run one of the tiny "personal" web servers, save the file to its file store (where you would have direct access), and then load the file from the web server (at address localhost or 127.0.0.1). That would be easier and faster than uploading via FTP to a remote server."


the source code that Gustav kindly sent cannot be directly used:

"but, sadly, that doesn't make a difference; the control still refuses to run the script as - even when not written to a file - is regarded as "local".!


so a question remains (shall I put this thought another question? "how do I

"run one of the tiny "personal" web servers, save the file to its file store " and "then load the file from the web server (at address localhost or 127.0.0.1)"?

can someone hand me a piece of code?

I am using this site as source for all my [strMap] coding:

http://www.bing.com/api/maps/sdk/mapcontrol/isdk#pushpinLabels+JS

it contains all necessary java and html (although on java is operational) for my requirements so, for me, I would just have to generate the things I need using this piece of code... (all I want is to put some pushpins and labels...
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
If you have a non-Home edition of Windows, the native IIS is included - just click as installed option.

But IIS is kind of overkill. You can bing/google for smal and basic web servers, one is here:

    https://sourceforge.net/projects/miniweb/

/gustav
0
 

Author Comment

by:jirdeaid
Comment Utility
Ok.

I have downloaded and ran the .exe.

but now I am out of options. I just have the below screen:


any hints?
Screen-Shot-2016-11-15-at-14.43.00.png
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
Copy/create your mappage.html file in the web root folder.

Open this URL (for a start in your browser):  

    http://localhost:8000/mappage.html

or

    http://10.211.55.3:8000/mappage.html

/gustav
0
 

Author Comment

by:jirdeaid
Comment Utility
well... improving (I think)

I am gettong a 404, but the cmd line is:


Host: 10.211.55.3:8000
Web root: \\Mac\Home\Desktop\miniweb\htdocs
Max clients (per IP): 32 (16)
URL handlers: 2
Dir listing enabled
[476] connection accepted
[476] IP: 127.0.0.1
Connected clients: 1
[476] request path: mappage.html
[476] Http file not found
[476] socket closed after responded for 1 requests
Connected clients: 1
[476] connection accepted
[476] IP: 127.0.0.1
Connected clients: 1
[476] socket closed by client
[476] socket closed after responded for 0 requests
Connected clients: 1
[480] connection accepted
[480] IP: 10.211.55.3
Connected clients: 1
[480] request path: mappage.html
[480] Http file not found
[480] socket closed after responded for 1 requests
Connected clients: 1
[480] connection accepted
[480] IP: 10.211.55.3
Connected clients: 1
[480] request path: mappage.html
[480] Http file not found
[480] socket closed after responded for 1 requests
Connected clients: 1
[476] connection accepted
[476] IP: 10.211.55.2
Connected clients: 1
[504] connection accepted
[504] IP: 10.211.55.2
Connected clients: 2
[476] request path: mappage.html
[476] Http file not found
[476] socket closed after responded for 1 requests
Connected clients: 2
[504] request path: favicon.ico
[504] 233 bytes sent (233 KB/s)
[504] 3231 bytes sent (3231 KB/s)
[504] socket closed after responded for 1 requests
Connected clients: 1
0
 

Author Comment

by:jirdeaid
Comment Utility
I think that I now it would be possible  to change the code that you have sent me so the "html" or "java" file may be "uploaded"?
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
It seems to work fine, except that you have copied the mappage.html to a wrong folder.
Study the documentation.

/gustav
0
 

Author Comment

by:jirdeaid
Comment Utility
Hi Gustav and Ryan -

I really want to close this matter, that started 10 days ago.

Gustav, mostly, pointed me to the solution: store the file on a local  web server  (miniWEB) which I can install in all access FE workstations. along with all FE data. (in the beginning, the BE will just be a virtual external disk for all), also containing common folders, such as images.

I can also store the file on an external web server, which I own (www.think.gw)

I could find no documentation for miniweb (neither on sourceforge nor googling), and, for me, programming over the web is totally unchartered territory.

so it is a bit like drowning really close to the beach.

I realize that, the situation is becoming a bit out of the core of the initial question and I still need help to:

- how to store the files either on my server or on the local server (I think that, in my server it would be preferable because I do not have to install miniwebs allover the place, but I may be totally wrong)
- how to get those files to work with the control (preferable in java as it is more compact than html

I would expect that this help would take no more than a couple of hours to a knowledgeable person like you - but will take me maybe 20 times more for a person like me and with potentially questionnable results.

I understand that I could hire a specialist from Experts Exchange that could help me close the matter and the cost is quoted. I believe that I can personally support this cost (this is an unpaid programme in Guinea-Bissau - Africa) and I work as a volunteer on this specific matter.

So can you please point me to someone that could help me complete the job? This means:

- help on the manner to store  the files (I have the source code for the files from microsoft, which I may modify)
- help on programming the web browser to interpret the files (I just need for one, of course)

thanks in advance
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
Did you manage to copy mappage.html to the document folder?

The help is called with the command line switch -h:
miniweb -h
Usage: miniweb -h | -u : display this help screen
-v : log status/error info
-p : specifiy http port [default 8000]
-r : specify http document directory [default .]
-l : specify log file
-m : specifiy max clients [default 32]
-M : specifiy max clients per IP
-n : disallow multi-part download
-d : disallow directory listing [default ON]

Open in new window

So you should be able to view status with -v and set the document folder with -r

/gustav
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jirdeaid
Comment Utility
Hi Gustav -

It is hapenning and I will be out form a pina collada

it started miniweb :


ss1
(I started it by double clicking on the .exe icon) - at this stage it does not accept any commands

then I generated the mappage.html using your code and copied it to the htdocs folder (and also to the folder containing the miniweb)

then, on the browser (chrome) I tried both:

http://10.211.55.3:8000/mappage.html (got a page!)

and

http://localhost:8000/mappage.html (site can't be reached)

and got this final result:

ss2
now you see where I live: the 4th poorest country in the entire world


What is the next step?


/joao
0
 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 300 total points
Comment Utility
All you need should be to adjust the path and url in the latest code:
Option Compare Database
Option Explicit

Private Sub btnGo_Click()
   
    Dim WebBrowser  As Object
    Dim strMap      As String
    Dim FileName    As String
    
    Set WebBrowser = Me!ctlWebBrowser
    
    strMap = "<!DOCTYPE html>" & vbCrLf
    strMap = strMap & "<!-- saved from url=(0014)about:internet -->" & vbCrLf
    strMap = strMap & "<html>" & vbCrLf
    strMap = strMap & "<head> " & vbCrLf
    strMap = strMap & "    <title>pushpinLabelsHTML</title>" & vbCrLf
    strMap = strMap & "    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>" & vbCrLf
    strMap = strMap & "</head>" & vbCrLf
    strMap = strMap & "<script type='text/javascript'>" & vbCrLf
    strMap = strMap & "    function loadMapScenario() {" & vbCrLf
    strMap = strMap & "        var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {" & vbCrLf
    strMap = strMap & "            credentials: 'Your Bing Maps Key'" & vbCrLf
    strMap = strMap & "            });" & vbCrLf
    strMap = strMap & "        var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), {" & vbCrLf
    strMap = strMap & "            text: 'A', " & vbCrLf
    strMap = strMap & "            title: 'Title', " & vbCrLf
    strMap = strMap & "            subTitle: 'Subtitle'" & vbCrLf
    strMap = strMap & "            });" & vbCrLf
    strMap = strMap & "        map.entities.push(pushpin);" & vbCrLf
    strMap = strMap & "    }" & vbCrLf
    strMap = strMap & "</script>" & vbCrLf
    strMap = strMap & "<body> " & vbCrLf
    strMap = strMap & "    <div id='printoutPanel'>" & vbCrLf
    strMap = strMap & "        <div id='myMap' style='width: 100vw; height: 100vh;'>" & vbCrLf
    strMap = strMap & "            <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?branch=release&callback=loadMapScenario' async defer></script>" & vbCrLf
    strMap = strMap & "        </div>" & vbCrLf
    strMap = strMap & "    </div>" & vbCrLf
    strMap = strMap & "</body>" & vbCrLf
    strMap = strMap & "</html>"
    
'    MsgBox strMap
'    Debug.Print strMap
    FileName = Application.CurrentProject.Path & "\mappage.html"

' Change to the document path of the web server:
FileName = "<insert web server path>" & "\mappage.html"

    Call WriteFile(FileName, strMap)
    
    ' Then continue.
    
    WebBrowser.Navigate "http:///10.211.55.3:8000/mappage.html")

' or two slashes:
'    WebBrowser.Navigate "http:///10.211.55.3:8000//mappage.html")

End Sub

Sub WriteFile(ByVal FilePath As String, ByVal Content As String)

    Const fsoForWriting = 2
    
    Dim objFSO As Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    ' Open the file.
    Dim objTextStream As Object
    Set objTextStream = objFSO.OpenTextFile(FilePath, fsoForWriting, True)
    
    ' Write the contents to the text file
    objTextStream.WriteLine Content
    
    ' Close the file and clean up.
    objTextStream.Close
    Set objTextStream = Nothing
    Set objFSO = Nothing

End Sub

Open in new window

Of course, if you don't change the mappage.html file, you only need to create it once.

/gustav
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
Also try this URL which will never change - what the 10-address might do:

    http://127.0.0.1:8000/mappage.html (got a page!)

/gustav
0
 

Author Comment

by:jirdeaid
Comment Utility
Hi my code now is:


    Dim strMap      As String
    Dim FileName    As String
   
    Set WebBrowser = Me!ctlWebBrowser
   
    strMap = "<!DOCTYPE html>" & vbCrLf
    strMap = strMap & "<!-- saved from url=(0014)about:internet -->" & vbCrLf
    strMap = strMap & "<html>" & vbCrLf
    strMap = strMap & "<head> " & vbCrLf
    strMap = strMap & "    <title>pushpinLabelsHTML</title>" & vbCrLf
    strMap = strMap & "    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>" & vbCrLf
    strMap = strMap & "</head>" & vbCrLf
    strMap = strMap & "<script type='text/javascript'>" & vbCrLf
    strMap = strMap & "    function loadMapScenario() {" & vbCrLf
    strMap = strMap & "        var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {" & vbCrLf
    strMap = strMap & "            credentials: 'Your Bing Maps Key'" & vbCrLf
    strMap = strMap & "            });" & vbCrLf
    strMap = strMap & "        var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), {" & vbCrLf
    strMap = strMap & "            text: 'A', " & vbCrLf
    strMap = strMap & "            title: 'Title', " & vbCrLf
    strMap = strMap & "            subTitle: 'Subtitle'" & vbCrLf
    strMap = strMap & "            });" & vbCrLf
    strMap = strMap & "        map.entities.push(pushpin);" & vbCrLf
    strMap = strMap & "    }" & vbCrLf
    strMap = strMap & "</script>" & vbCrLf
    strMap = strMap & "<body> " & vbCrLf
    strMap = strMap & "    <div id='printoutPanel'>" & vbCrLf
    strMap = strMap & "        <div id='myMap' style='width: 100vw; height: 100vh;'>" & vbCrLf
    strMap = strMap & "            <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?branch=release&callback=loadMapScenario' async defer></script>" & vbCrLf
    strMap = strMap & "        </div>" & vbCrLf
    strMap = strMap & "    </div>" & vbCrLf
    strMap = strMap & "</body>" & vbCrLf
    strMap = strMap & "</html>"
   
'    MsgBox strMap
'    Debug.Print strMap
    FileName = Application.CurrentProject.Path & "\mappage.html"

' Change to the document path of the web server:
FileName = "\\Mac\Home\Desktop\siresh-gb 03 desktop\miniweb" & "\mappage.html"

    Call WriteFile(FileName, strMap)
   
    ' Then continue.
   
   WebBrowser.Navigate ("http://127.0.0.1:8000/mappage.html ")

' or two slashes:
'    WebBrowser.Navigate "http:///10.211.55.3:8000//mappage.html")

End Sub

Sub WriteFile(ByVal FilePath As String, ByVal Content As String)

    Const fsoForWriting = 2
   
    Dim objFSO As Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
   
    ' Open the file.
    Dim objTextStream As Object
    Set objTextStream = objFSO.OpenTextFile(FilePath, fsoForWriting, True)
   
    ' Write the contents to the text file
    objTextStream.WriteLine Content
   
    ' Close the file and clean up.
    objTextStream.Close
    Set objTextStream = Nothing
    Set objFSO = Nothing

End Sub



When I open MAPPAGE on the folder with Edge it's ok

however, on the test database (on the control) it yields:

ss1
and when I refresh the page:

ss2

any ideas?
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
Not really, sorry, except that in your Internet Explorer settings scripting is marked as not allowed.

You can open the page with Edge, but how about IE?

/gustav
0
 

Author Comment

by:jirdeaid
Comment Utility
Explorer does not work - it yields the same error.

I recall some comments on a separate track, maybe even by you, that explorer by default goes to version 7 which is said that is useless. Do you know something about it?

/joao
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
Sorry, no. Perhaps the missing script option is a permanent limitation of the browser control.

I tried to call:

    Application.FollowHyperlink "file:///c:/test/mappage.html"

but that doesn't work on my Windows 10 where Edge is the default browser. It just displays a blank page.
But if your users default browser is not Edge, it may work. A separate window, I know, but at least a map is displayed.

/gustav
0
 

Author Comment

by:jirdeaid
Comment Utility
Well... please have a look at the below screenshots:


Screen-Shot-2016-11-17-at-19.45.22.png

and


Screen-Shot-2016-11-17-at-19.45.34.png

they come from the site that I am willing to mimic from microsoft.

You see that there is a warning showing that only in java they show something


could this be the reason?
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
No it says Javascript, not Java two different things. To me it tells, that if Javascript would be executed, a map would be shown at this place - which is true.

I've located this which gives a meaningful clue:

http://www.devhut.net/2013/10/18/webbrowser-activex-control-google-maps-invalid-character-scripting-error/

that the browser control defaults to an old version mode of IE. Try to follow the guide.

/gustav
0
 

Author Comment

by:jirdeaid
Comment Utility
ok. It will take some hours as I need to debug another part of the database that is jumping alone....
0
 

Author Comment

by:jirdeaid
Comment Utility
Hi Gustav -

I will close the question RSN, as I think that, now, I am on the path.

What I did: I have changed the strmap to JavaScript

I suspected that the problem lied elsewhere because the site where I pick the code from (I have shared the link and screenshot above) tells that it works only in javascript although it shows code for HTML / Javascript and  Typescript (I ain't the faintest idea that it existed at all and, anyway it is the same as Javascript, at least looking into the examples...)

So now it works (sort of) as you may see from the screenshot:

Screen-Shot-2016-11-18-at-20.57.18.png
(I am also uploading the test database so you may check)

Unfortunately, I am stuck again. this site in reality is a fake from microsoft.

I have modified the code to test (inserted my Bing key and  modified the title / subtitle and pushpin labels) and got exactly the same page content as if I did not modify a single letter (!)

So I need to post another question on how to put a HTML or Javascript to work either with bing or google maps (for now, I just want to put some pushpin and labels) on the map, but, at least we got some progress...

I will just wait some comment from you and close the question

thanks!
TESTES-WEB-BROWSER.accdb
0
 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 300 total points
Comment Utility
Maybe you need to set the coordinates of the center?
I run similar code in a ASP.NET MVC page:
<script type='text/javascript'>
    var map;
    var pushpin;
    function loadMapScenario() {
        map = new Microsoft.Maps.Map(document.getElementById('bingMap'), {
            credentials: '@Html.Raw(@mapViewModel.Credentials)',
            center: new Microsoft.Maps.Location(@mapViewModel.Latitude, @mapViewModel.Longitude),
            zoom: @mapViewModel.Zoom });
        pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), {
            text: '@Html.Raw(@mapViewModel.PinText)',
            title: '@Html.Raw(@mapViewModel.PinTitle)',
            subTitle: '@Html.Raw(@mapViewModel.PinSubTitle)' });
        map.entities.push(pushpin);
    }
</script>

Open in new window

which works as intended: Bing Map Demo

/gustav
0
 
LVL 32

Expert Comment

by:Stefan Hoffmann
Comment Utility
What's wrong with a local file?

See attachment. Store the html file in C:\Temp.
BingMaps.accdb
map.html
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
Stephan, no problem for a fixed, local file. However:

https://www.experts-exchange.com/questions/28981587/using-web-browser-with-BING.html#a41885351

/gustav
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
Stephan, it's no problem for static files.
The issue is the integrity level for dynamically created files; run the database from the link above, replace the code with mine, and you'll see.

/gustav
0
 
LVL 32

Accepted Solution

by:
Stefan Hoffmann earned 200 total points
Comment Utility
The key is: there is no need for dynamic files. You load your HTML and necessary files only once. The rest is injected either into the DOM directly or by using JavaScript functions which are already part of your file:

<!-- saved from url=(0016)http://localhost -->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>pushpinLabelsHTML</title>
		<script type="text/javascript" src="http://www.bing.com/api/maps/mapcontrol?branch=release&callback=loadMapScenario" async defer></script>
		<script type="text/javascript">
			var map;
			function loadMapScenario() {
				 map = new Microsoft.Maps.Map(document.getElementById("myMap"), { credentials: "secret-bing-key" });
				addPushpin(map.getCenter().latitude,map.getCenter().longitude, "A", "Title", "Subtitle");
			}
			function addPushpin(lat, lon, text, title, subtitle) {
				var pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(lat, lon), { text: text, title: title, subTitle: subtitle });
				map.entities.push(pushpin);
			}
		</script>
	</head>
	<body> 		
		<div id="myMap" style="width: 100vw; height: 100vh;"></div>
	</body>
</html>

Open in new window


So we can call it in VBA:

Option Compare Database
Option Explicit

Private WithEvents m_WebBrowser As SHDocVw.WebBrowser

Private Sub btnCenter_Click()

  InvokeJavaScript "addPushpin(0, 0, 'C', 'Middle of the Earth', 'Maybe dragons.');"

End Sub

Private Sub btnLoadFile_Click()

  Set m_WebBrowser = ctlWebBrowser.Object
  m_WebBrowser.Navigate "c:\temp\map.html"

End Sub

Private Sub InvokeJavaScript(AScript As String)

  On Local Error GoTo LocalError

  m_WebBrowser.Document.parentWindow.execScript AScript
  
  Exit Sub
  
LocalError:
  MsgBox Err.Description

End Sub

Open in new window


Think in terms of MVVM/MVC pattern. Where the HTML page is the view, Access the "model" and JavaScript holds the viewmodel/controller.
BingMaps.accdb
map.html
0
 

Author Comment

by:jirdeaid
Comment Utility
Ok! Now I am seeing heavenly forms.

With the miniweb approach I getting stuck because somehow it does never recognise my bing key and I can't change the pushpins anyway. With Stephan's approach I can avoid installing miniweb on a number of machines and stick to plain vanilla vba, as long as I can predefine a number of "template" pages for all my needs (the "map.html" file from Stephan differs somehow from the original microsoft html page, which makes me enter into panic.

My current needs are (I suppose) not terrible:

* show a number of pushpins, not just one, with respective labels
* using a images (with transparency) as push-pin so people could se behind them.
* ensuring that the page loads at a specific lat/lon coordinate
* getting coordinates and
* setting options like hover

all those are well demonstrated in the site I have used as source for this: http://www.bing.com/api/maps/sdk/mapcontrol/isdk#setPushpinOptions+JS

Thus I have a question: all this "requirements" would end up in adding functions like "function addPushpin(lat, lon, text, title, subtitle)"
to a single template "maps.html" file?

Is this the correct approach?
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
I can predefine a number of "template" pages for all my needs

That seems to be the only option. You will have to specify in these altitude and longitude as mentioned in my last code snippet:
<script type='text/javascript'>
    var map;
    var pushpin;
    function loadMapScenario() {
        map = new Microsoft.Maps.Map(document.getElementById('bingMap'), {
            credentials: '@Html.Raw(@mapViewModel.Credentials)',
            center: new Microsoft.Maps.Location(@mapViewModel.Latitude, @mapViewModel.Longitude),
            zoom: @mapViewModel.Zoom });
        pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), {
            text: '@Html.Raw(@mapViewModel.PinText)',
            title: '@Html.Raw(@mapViewModel.PinTitle)',
            subTitle: '@Html.Raw(@mapViewModel.PinSubTitle)' });
        map.entities.push(pushpin);
    }
</script>

Open in new window

The @-variables must be replaced with your actual values. Altitude and longitude are decimals formatted as text with dot as the separator. You can copy and paste these from the real Bing map.

For every page you modify, open it in Edge and save it with its final name. This file will have the integrity level set so it can be opened and displayed with the browser control.

/gustav
0
 

Author Closing Comment

by:jirdeaid
Comment Utility
Hi.

I am closing now this question - it took a great effort, mostly from Gustav, so I'm giving a bit more points to him. For involved effort I should be able to award at least 5,000 points... But I can't. I will now pursue the parameterisation on the real database of the solution, starting in this simple page and then progressing with experts-exchange help (I am really keen on it, being a faithfull paying customer for many years now).

So many thanks for helping me.

/joao (from guinea-bissau)
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
You are welcome!

It was a surprise to me, that this is such a convoluted a task.

/gustav
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now