IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBA Access Discussion :

Web browser & HTML


Sujet :

VBA Access

  1. #1
    Membre confirmé
    Homme Profil pro
    AutoEntrepreneur Photo
    Inscrit en
    Avril 2015
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : AutoEntrepreneur Photo
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2015
    Messages : 141
    Par défaut Web browser & HTML
    Bonjour à tous,

    Je souhaite ouvrir une page HTML via le Web Browser d'access.
    Jusque là j'utilisais
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      Me.ctlNav.Object.Navigate CurrentProject.Path & "\ee.html"
    ctlNav étant le web browser et ee.html, la page html à charger.

    Enfaite, j'ai un bout de code qui me permet de modifier / créer le code html du fichier ee.html
    J'aimerai m'affranchir de ce fichier et je me demandais s'il n'existait pas à moyen de coder le HTML à afficher dans le web browser au lieu de créer un fichier HTML qui sera lu par le web browser???

    C'est comme ça que j'ai trouvé ce code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
       ' Dim HTML As String
           ' HTML = "<HTML>"
                'HTML = HTML & "<p> Preview my HTML string </p>"
            'HTML = HTML & "</HTML>"
     
        'Dim obj As HTMLDocument
           'Set obj = ctlNav.Document
           'obj.Body.innerHTML = HTML
    Mais ça me provoque un problème de "With" chez moi...

    Auriez vous des pistes?

    En vous remerciant

    zunk

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    j'ai fais ce bout de code dans Excel mais dans Access c'est pareil!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    Option Explicit
    Property Let strHTML(value As String)
    WebBrowser1.Document.body.innerhtml = value
    End Property
    Property Get strHTML() As String
    strHTML = WebBrowser1.Document.body.innerhtml
    End Property
    Private Sub UserForm_Initialize()
     Dim HTML As String
            HTML = "<HTML>" & _
            "<p> Preview my HTML string </p>" & _
             "</HTML>"
     Me.WebBrowser1.Navigate "about:blank"
         strHTML = HTML
    End Sub

  3. #3
    Membre confirmé
    Homme Profil pro
    AutoEntrepreneur Photo
    Inscrit en
    Avril 2015
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : AutoEntrepreneur Photo
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2015
    Messages : 141
    Par défaut
    Bonjour dysorthographie,
    Merci pour ta réponse.

    J'ai donc recopier ton code mais je retombe sur une erreur: "Variable objet ou variable de bloc with non définie"
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    Option Compare Database
     
     
    Option Explicit
    Property Let strHTML(value As String)
    Me.ctlNav.Document.Body.innerHTML = value
    End Property
    Property Get strHTML() As String
    strHTML = Me.ctlNav.Document.Body.innerHTML
    End Property
    Private Sub Commande1_Click()
     Dim HTML As String
            HTML = "<HTML>" & _
            "<p> Preview my HTML string </p>" & _
             "</HTML>"
     Me.ctlNav.Navigate "about:blank"
         strHTML = HTML
    End Su
    Aurais tu une idée?

    Merci

  4. #4
    Invité
    Invité(e)
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    Option Compare Database
    Property Let strHTML(value As String)
    ctlNav.Document.Body.innerHTML = value
    End Property
    Property Get strHTML() As String
    strHTML = ctlNav.Document.Body.innerHTML
    End Property
    Private Sub Commande1_Click()
     Dim HTML As String
            HTML = "<HTML>" & _
            "<p> Preview my HTML string </p>" & _
             "</HTML>"
         ctlNav.Navigate "about:blank"
         strHTML = HTML
    End Sub

  5. #5
    Membre confirmé
    Homme Profil pro
    AutoEntrepreneur Photo
    Inscrit en
    Avril 2015
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : AutoEntrepreneur Photo
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2015
    Messages : 141
    Par défaut
    Merci pour l'aide.
    Donc plus de msg d'erreur, mais le webbrowser n'affiche rien, or il devrait afficer "PReview my string" nan?

  6. #6
    Invité
    Invité(e)
    Par défaut
    Désolé!
    Code marche chez moi! : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Property Let strHTML(value As String)
    With ctlNav
        Do: DoEvents: Loop While .ReadyState <> 4 Or .Busy
        .Document.Body.innerHTML = value
        DoEvents
        End With
    End Property

  7. #7
    Membre confirmé
    Homme Profil pro
    AutoEntrepreneur Photo
    Inscrit en
    Avril 2015
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : AutoEntrepreneur Photo
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2015
    Messages : 141
    Par défaut
    Merci beaucoup !
    Effectivement ça marche nickel !

    PAr contre je n'arrive pas à adapter mon code.

    Peut être car il contient du JavaScript?
    La première partie qui pose problème est :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    HTML = "<HTML>" & _
            "<head><style>#map {height: 250px;width: 80%;}</style></head><body><h3>My Google Maps Demo</h3><div id="map"></div><script>" & _
    Il ne comprend pas le langage utilisé (par exemple les " avant/après: map

    La deuxième partie du code qui pose problème:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    "</script><script async defer" & _
        src="https://maps.googleapis.com/maps/api/js?key=XXXCLEEAPIGOOGLEMAP">
        </script>
    à savoir que le webbrowser est capable d'afficher la page souhaitée, avec mon ancienne méthode qui lance le fichier .html avec le code suivant:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <html>
      <head>
        <style>
           #map {
            height: 250px;
            width: 80%;
           }
        </style>
      </head>
      <body>
        <h3>My Google Maps Demo</h3>
        <div id="map"></div>
        <script>
          function initMap() {
            var uluru = {lat: -21.0207796666667, lng: 55.2382640555556};
    	var ulurumap = {lat: -21.117022, lng: 55.530767};
            var map = new google.maps.Map(document.getElementById('map'), {
              zoom: 9,
              center: ulurumap
            });
            var marker = new google.maps.Marker({
              position: uluru,
              map: map
            });
          }
        </script>
        <script async defer
        src="https://maps.googleapis.com/maps/api/js?key=XXXCLEEAPIGOOGLEMAP&callback=initMap">
        </script>
      </body>
    </html>
    Comment l'adapter?

    Merci

  8. #8
    Invité
    Invité(e)
    Par défaut
    on a pas été très honnête avec notre amis webbroser! nous l'informons qu'il travail sur une page blanche et dans son dos on modifie le document html avec feuille de style java script !

    il nous demande un peut plus de respect!

    nous allons tenté de le satisfaire! pour ce faire nous allons inhiber le java script .Silent = True modifier le code html, réactiver le java script puis rafraichir la page!
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Option Compare Database
    Property Let strHTML(value As String)
    With ctlNav
        Do: DoEvents: Loop While .ReadyState <> 4 Or .Busy
        .Silent = True
        .Document.Body.innerHTML = ""
        .Document.Write value
        .Silent = False
        .Refresh
        DoEvents
        End With
    End Property
    Function Html() As String
    Html = "<html>" & vbCrLf
    Html = Html & "  <head>" & vbCrLf
    Html = Html & "    <style>" & vbCrLf
    Html = Html & "       #map {" & vbCrLf
    Html = Html & "        height: 250px;" & vbCrLf
    Html = Html & "        width: 80%;" & vbCrLf
    Html = Html & "       }" & vbCrLf
    Html = Html & "    </style>" & vbCrLf
    Html = Html & "  </head>" & vbCrLf
    Html = Html & "  <body>" & vbCrLf
    Html = Html & "    <h3>My Google Maps Demo</h3>" & vbCrLf
    Html = Html & "    <div id='map'></div>" & vbCrLf
    Html = Html & "    <script>" & vbCrLf
    Html = Html & "      function initMap() {" & vbCrLf
    Html = Html & "        var uluru = {lat: -21.0207796666667, lng: 55.2382640555556};" & vbCrLf
    Html = Html & "    var ulurumap = {lat: -21.117022, lng: 55.530767};" & vbCrLf
    Html = Html & "        var map = new google.maps.Map(document.getElementById('map'), {" & vbCrLf
    Html = Html & "          zoom: 9," & vbCrLf
    Html = Html & "center:           ulurumap" & vbCrLf
    Html = Html & "        });" & vbCrLf
    Html = Html & "        var marker = new google.maps.Marker({" & vbCrLf
    Html = Html & "          position: uluru," & vbCrLf
    Html = Html & "map:           map" & vbCrLf
    Html = Html & "        });" & vbCrLf
    Html = Html & "      }" & vbCrLf
    Html = Html & "    </script>" & vbCrLf
    Html = Html & "    <script async defer" & vbCrLf
    Html = Html & "    src='https://maps.googleapis.com/maps/api/js?key=XXXCLEEAPIGOOGLEMAP&callback=initMap'>" & vbCrLf
    Html = Html & "    </script>" & vbCrLf
    Html = Html & "  </body>" & vbCrLf
    Html = Html & "</html>"
    End Function
    Property Get strHTML() As String
    strHTML = ctlNav.Document.Body.innerHTML
    End Property
    Private Sub Commande1_Click()
    ' Dim Html As String
    '        Html = "<HTML>" & _
    '        "<p> Preview my HTML string </p>" & _
    '         "</HTML>"
     Me.ctlNav.Navigate "about:blank"
     
         strHTML = Html
     
     
    End Sub

  9. #9
    Membre confirmé
    Homme Profil pro
    AutoEntrepreneur Photo
    Inscrit en
    Avril 2015
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : AutoEntrepreneur Photo
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2015
    Messages : 141
    Par défaut
    Excellent !! Webbrowser à l'air d'aimer ça :o ça fonctionne !

    Pour couronner le tout, je souhaiterai insérer des variables (des coordonnées) à intégrer dans la fonction
    strLat et strLng
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Html = Html & "        var uluru = {lat: strLat, lng: strLng};" & vbCrLf
    Html = Html & "    var ulurumap = {lat:  -21.117022, lng: 55.530767};" & vbCrLf
    Comment m'y prendre?

    encore merci pour ce code génial qui me permet de faire fonctionner la googleAPI Javascript !

  10. #10
    Membre confirmé
    Homme Profil pro
    AutoEntrepreneur Photo
    Inscrit en
    Avril 2015
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : AutoEntrepreneur Photo
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2015
    Messages : 141
    Par défaut
    En plus de m'affranchir de créer un document .HTML, la solution de simuler une page blanche et la coder permet également d'outrepasser les problème de "Demande d'autorisation pour activer le contenu ActiveX" (qui nécessite un clique de l'utilisateur) !!! et c'était justement un des autres points qui me posait problème !!!! génial

  11. #11
    Invité
    Invité(e)
    Par défaut
    avec paramétrages!
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Option Compare Database
    Property Let strHTML(value As String)
    With ctlNav
        Do: DoEvents: Loop While .ReadyState <> 4 Or .Busy
        .Silent = True
        .Document.Body.innerHTML = ""
        .Document.Write value
        .Silent = False
        .Refresh
        DoEvents
        End With
    End Property
    Function Html(lat As String, lng As String) As String
    Html = "<html>" & vbCrLf
    Html = Html & "  <head>" & vbCrLf
    Html = Html & "    <style>" & vbCrLf
    Html = Html & "       #map {" & vbCrLf
    Html = Html & "        height: 250px;" & vbCrLf
    Html = Html & "        width: 80%;" & vbCrLf
    Html = Html & "       }" & vbCrLf
    Html = Html & "    </style>" & vbCrLf
    Html = Html & "  </head>" & vbCrLf
    Html = Html & "  <body>" & vbCrLf
    Html = Html & "    <h3>My Google Maps Demo</h3>" & vbCrLf
    Html = Html & "    <div id='map'></div>" & vbCrLf
    Html = Html & "    <script>" & vbCrLf
    Html = Html & "      function initMap() {" & vbCrLf
    Html = Html & "        var uluru = {lat: " & lat & " , lng: " & lng & "};" & vbCrLf
    Html = Html & "    var ulurumap = {lat: " & lat & " , lng: " & lng & "};" & vbCrLf
    Html = Html & "        var map = new google.maps.Map(document.getElementById('map'), {" & vbCrLf
    Html = Html & "          zoom: 9," & vbCrLf
    Html = Html & "center:           ulurumap" & vbCrLf
    Html = Html & "        });" & vbCrLf
    Html = Html & "        var marker = new google.maps.Marker({" & vbCrLf
    Html = Html & "          position: uluru," & vbCrLf
    Html = Html & "map:           map" & vbCrLf
    Html = Html & "        });" & vbCrLf
    Html = Html & "      }" & vbCrLf
    Html = Html & "    </script>" & vbCrLf
    Html = Html & "    <script async defer" & vbCrLf
    Html = Html & "    src='https://maps.googleapis.com/maps/api/js?key=XXXCLEEAPIGOOGLEMAP&callback=initMap'>" & vbCrLf
    Html = Html & "    </script>" & vbCrLf
    Html = Html & "  </body>" & vbCrLf
    Html = Html & "</html>"
    End Function
    Property Get strHTML() As String
    strHTML = ctlNav.Document.Body.innerHTML
    End Property
    Private Sub Commande1_Click()
    ' Dim Html As String
    '        Html = "<HTML>" & _
    '        "<p> Preview my HTML string </p>" & _
    '         "</HTML>"
     Me.ctlNav.Navigate "about:blank"
     
         strHTML = Html("-21.0207796666667", "55.2382640555556")
        DoEvents
     
     
    End Sub

  12. #12
    Membre confirmé
    Homme Profil pro
    AutoEntrepreneur Photo
    Inscrit en
    Avril 2015
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : AutoEntrepreneur Photo
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2015
    Messages : 141
    Par défaut
    Merci beaucoup ça fonctionne super bien. J'ai même l'impression que les pages se chargent plus vites avec cette méthode.

    Mais alors je me dit que si le webbrowser est capable de lancer une requête Javascript via VBA, et d'afficher la réponse dans le browser, serait il possible de faire la manip "inverse" consistant à récupérer le résultat de la requête Javascript chargée par le webbrowser?

    exemple concret:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Property Let strHTML(value As String)
    With ctlNav
        Do: DoEvents: Loop While .ReadyState <> 4 Or .Busy
        .Silent = True
        .Document.Body.innerHTML = ""
        .Document.Write value
        .Silent = False
        .Refresh
        DoEvents
        End With
    End Property
    Function Html() As String
     
      Html = "<html>" & vbCrLf
    Html = Html & "  <head>" & vbCrLf
        Html = Html & "  <meta name='viewport' content='initial-scale=1.0, user-scalable=no'>" & vbCrLf
        Html = Html & "  <meta charset='utf-8'>" & vbCrLf
        Html = Html & "  <title>Elevation service</title>" & vbCrLf
        Html = Html & "  <style>" & vbCrLf
          '/* Always set the map height explicitly to define the size of the div"
           'element that contains the map. */" & vbCrLf
          Html = Html & "  #map {" & vbCrLf
            Html = Html & "  height: 100%;" & vbCrLf
          Html = Html & "  }" & vbCrLf
       Html = Html & "html, body {" & vbCrLf
            Html = Html & "  height: 100%;" & vbCrLf
            Html = Html & "  margin: 0;" & vbCrLf
            Html = Html & "  padding: 0;" & vbCrLf
          Html = Html & "  }" & vbCrLf
        Html = Html & "  </style>" & vbCrLf
     Html = Html & "   </head>" & vbCrLf
      Html = Html & "  <body>" & vbCrLf
        Html = Html & "  <div id='map'></div>" & vbCrLf
        Html = Html & "  <script>" & vbCrLf
          Html = Html & "  function initMap() {" & vbCrLf
            Html = Html & "  var map = new google.maps.Map(document.getElementById('map'), {" & vbCrLf
              Html = Html & "  zoom: 8," & vbCrLf
              Html = Html & "  center: {lat: 63.333, lng: -150.5},  // Denali." & vbCrLf
    Html = Html & "  mapTypeId:           'terrain'" & vbCrLf
           Html = Html & "   });" & vbCrLf
           Html = Html & "   var elevator = new google.maps.ElevationService;" & vbCrLf
            Html = Html & "  var infowindow = new google.maps.InfoWindow({map: map});" & vbCrLf
     
            '// Add a listener for the click event. Display the elevation for the LatLng of
            '// the click inside the infowindow.
          Html = Html & "    map.addListener('click', function(event) {" & vbCrLf
          Html = Html & "      displayLocationElevation(event.latLng, elevator, infowindow);" & vbCrLf
          Html = Html & "    });" & vbCrLf
         Html = Html & "   }" & vbCrLf
     
          Html = Html & "  function displayLocationElevation(location, elevator, infowindow) {" & vbCrLf
            '// Initiate the location request
           Html = Html & "   elevator.getElevationForLocations({" & vbCrLf
            Html = Html & "    'locations': [location]" & vbCrLf
           Html = Html & "   }, function(results, status) {" & vbCrLf
            Html = Html & "    infowindow.setPosition(location);" & vbCrLf
            Html = Html & "    if (status === 'OK') {" & vbCrLf
                '// Retrieve the first result
             Html = Html & "     if (results[0]) {" & vbCrLf
                  '// Open the infowindow indicating the elevation at the clicked position.
              Html = Html & "      infowindow.setContent('The elevation at this point <br>is ' +" & vbCrLf
              Html = Html & "          results[0].elevation + ' meters.');" & vbCrLf
              Html = Html & "    } else {" & vbCrLf
              Html = Html & "      infowindow.setContent('No results found');" & vbCrLf
              Html = Html & "    }" & vbCrLf
              Html = Html & "  } else {" & vbCrLf
              Html = Html & "    infowindow.setContent('Elevation service failed due to: ' + status);" & vbCrLf
              Html = Html & "  }" & vbCrLf
            Html = Html & "  });" & vbCrLf
          Html = Html & "  }" & vbCrLf
        Html = Html & "  </script>" & vbCrLf
        Html = Html & "  <script async defer" & vbCrLf
        Html = Html & "  src='https://maps.googleapis.com/maps/api/js?key=AIzaSyBjNsr0Dk_MN7HEvOJ6aNzqVqc_PhxQKjg&callback=initMap' > " & vbCrLf
        Html = Html & "  </script>"
      Html = Html & "  </body>"
    Html = Html & "  </html>"
    End Function
    Property Get strHTML() As String
    strHTML = ctlNav.Document.Body.innerHTML
    End Property
    Private Sub Commande1_Click()
    ' Dim Html As String
    '        Html = "<HTML>" & _
    '        "<p> Preview my HTML string </p>" & _
    '         "</HTML>"
     Me.ctlNav.Navigate "about:blank"
     
         strHTML = Html
     
     
    End Sub
    Ce code permet de charger une map dans le webbrowser. Lorsque l'on clique sur la map, une donnée apparait (dans cet exemple: l'élévation). D'un point de vue javascript, une requête est d'élévation est lancée pour une "location". et le resultat de cette requête (l'élévation du point concerné) est récupéré via: results[0].elevation

    Est il donc possible de récupérer cette donnée ?

    Merci en tout cas pour toutes ces infos et pour cette super solution

  13. #13
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    si l'objectif est de seulement récupérer l'elevation d'une location connue (lat/lng), il y a plus simple et plus facilement automatisable

  14. #14
    Membre confirmé
    Homme Profil pro
    AutoEntrepreneur Photo
    Inscrit en
    Avril 2015
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : AutoEntrepreneur Photo
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2015
    Messages : 141
    Par défaut
    Bonjour galoir,
    le code ci dessus permet uniquement l'affichage d'une elevation en fonction d'un point selectionné.
    Mais ce n'est pas ce que je cherche à faire à terme.
    En effet, mon but à terme est de lancer une requête pour 512 lieux (limit max google api / requête) : coordonnées présentes dans une table et que la requête me permette de compléter automatiquement un champs "elevation_google" pour chacune des lignes.
    Edit: ceci dit obtenir l'élévation pour une coordonnée serait déjà une info intéressante.

  15. #15
    Invité
    Invité(e)
    Par défaut
    Voici une fonction pour récupérer l'élévation, à placer dans un module standard vba :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    'Public Type containing the geocoding of the postal address
    Public Type tElevationResult
       sStatus As String
       dElevation As Double
       dResolution As Double
       dRetLatitude As Double
       dRetLongitude As Double
    End Type
     
    Public Function GetElevation(ByVal Latitude As Double, ByVal Longitude As Double, Optional ByVal Key As String) As tElevationResult
    'dérivé d'un code de Philben
       On Error GoTo catch
       Dim oXmlDoc As Object
       Dim sUrl As String, sFormatAddress As String
     
       'To create the URL
       sUrl = "http://maps.googleapis.com/maps/api/elevation/xml?locations=" & Str(Latitude) & "," & Str(Longitude)
       If Key <> vbNullString Then sUrl = sUrl & "&key=" & Key
     
       ''XMLDOM to get the XML response
       Set oXmlDoc = CreateObject("Microsoft.XMLDOM")
       With oXmlDoc
          .Async = False
          If .Load(sUrl) And Not .selectSingleNode("ElevationResponse/status") Is Nothing Then
             'Status code
             GetElevation.sStatus = .selectSingleNode("ElevationResponse/status").Text
     
             'If a result is returned
             If Not .selectSingleNode("ElevationResponse/result") Is Nothing Then
     
                'Elevation
                GetElevation.dElevation = Val(.selectSingleNode("//elevation").Text)
     
                'Resolution
                GetElevation.dResolution = Val(.selectSingleNode("//resolution").Text)
     
                'Latitude et longitude retournées
                GetElevation.dRetLatitude = Val(.selectSingleNode("//location/lat").Text)
                GetElevation.dRetLongitude = Val(.selectSingleNode("//location/lng").Text)
             End If
          End If
       End With
       Set oXmlDoc = Nothing
       Exit Function
    catch:
       Set oXmlDoc = Nothing
       Err.Raise Err.Number, , Err.Description
    End Function
    et une fonction de test :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    Public Function ExempleElevation()
    Dim e As tElevationResult, s As String
     
    e = GetElevation(39.7391536, -104.9847034)
     
    s = "Status : " & e.sStatus & vbCrLf & _
        "Elevation : " & e.dElevation & vbCrLf & _
        "Résolution : " & e.dResolution & vbCrLf & _
        "Lat/Lon retournées : " & e.dRetLatitude & " / " & e.dRetLongitude
    MsgBox s, vbInformation, "Get Elevation"
    End Function
    Possibilité d'ajouter son apikey via paramètre de la fonction getElevation

    On peut donc facilement boucler sur x demandes avec un délai (>200ms) entre chaque appel

  16. #16
    Membre confirmé
    Homme Profil pro
    AutoEntrepreneur Photo
    Inscrit en
    Avril 2015
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : AutoEntrepreneur Photo
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2015
    Messages : 141
    Par défaut
    Merci pour ta fonction,
    si j'ai bien compris ton code:
    1) tu lances une requête html (requête simple pour obtenir 1 info sur une location)
    2) tu créés un fichier temporaire : oXmlDoc dans lequel tu vas pouvoir lire et récupérer les réponses de ta requête (statut, elevation, resolution, latlgn)

    Ne penses tu pas qu'il serait possible de faire une requête sur plusieurs locations:
    Spécification des points géographiques

    Les requêtes de position sont signalées par l'utilisation du paramètre locations, indiquant les requêtes d'altitude des points géographiques précis transmis sous forme de valeurs de latitude/longitude.

    Le paramètre locations peut prendre les arguments suivants :

    Une coordonnée unique : locations=40.714728,-73.998672
    Un tableau de coordonnées séparées à l'aide du caractère barre verticale (« | ») : locations=40.714728,-73.998672|-34.397,150.644
    https://developers.google.com/maps/d...on/intro?hl=fr

    En théorie google peut répondre un tableau de plusieurs locations en une seule requête..

  17. #17
    Invité
    Invité(e)
    Par défaut
    tout à fait c'est faisable, mais limite qd même la longueur de l'url

  18. #18
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    101
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 101
    Par défaut Retour sur webbrowser et Html
    Bonjour, j'affichais auparavant dans un form access un webbrowser me renvoyant un google maps des adresses de mon repertoire
    code de Philbel qui fonctionnait tres bien

    Mon fichier HTML D'origine ne fonctionne plus.

    J'ai donc tente de changer la methode en essayant de reprendre la votre et en obtenant une cle api google maps.

    Le code semble en tout point pareil au votre, la cle en plus:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    Property Let strHTML(value As String)
    With Me.WebBrowser
        Do: DoEvents: Loop While .ReadyState <> 4 Or .Busy
        .Silent = True
        .Document.Body.innerHTML = ""
        .Document.Write value
        .Silent = False
        .Refresh
        DoEvents
        End With
    End Property
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    Function Html(lat As String, lng As String) As String
    Html = "<html>" & vbCrLf
    Html = Html & "  <head>" & vbCrLf
    Html = Html & "    <style>" & vbCrLf
    Html = Html & "       #map {" & vbCrLf
    Html = Html & "        height: 250px;" & vbCrLf
    Html = Html & "        width: 80%;" & vbCrLf
    Html = Html & "       }" & vbCrLf
    Html = Html & "    </style>" & vbCrLf
    Html = Html & "  </head>" & vbCrLf
    Html = Html & "  <body>" & vbCrLf
    Html = Html & "    <h3>My Google Maps Demo</h3>" & vbCrLf
    Html = Html & "    <div id='map'></div>" & vbCrLf
    Html = Html & "    <script>" & vbCrLf
    Html = Html & "      function initMap() {" & vbCrLf
    Html = Html & "        var uluru = {lat: " & lat & " , lng: " & lng & "};" & vbCrLf
    Html = Html & "    var ulurumap = {lat: " & lat & " , lng: " & lng & "};" & vbCrLf
    Html = Html & "        var map = new google.maps.Map(document.getElementById('map'), {" & vbCrLf
    Html = Html & "          zoom: 9," & vbCrLf
    Html = Html & "center:           ulurumap" & vbCrLf
    Html = Html & "        });" & vbCrLf
    Html = Html & "        var marker = new google.maps.Marker({" & vbCrLf
    Html = Html & "          position: uluru," & vbCrLf
    Html = Html & "map:           map" & vbCrLf
    Html = Html & "        });" & vbCrLf
    Html = Html & "      }" & vbCrLf
    Html = Html & "    </script>" & vbCrLf
    Html = Html & "    <script async defer" & vbCrLf
    Html = Html & "    src='https://maps.googleapis.com/maps/api/js?key=AIzaSyBYoBtxj9jpYYS0yyGKlPd_joFyhWZ1CbA&callback=initMap'>" & vbCrLf
    Html = Html & "    </script>" & vbCrLf
    Html = Html & "  </body>" & vbCrLf
    Html = Html & "</html>"
    End Function
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    Property Get strHTML() As String
    strHTML = Me.WebBrowser.Document.Body.innerHTML
    End Property
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    Private Sub Cmd57_Click()
     Me.WebBrowser.Navigate "about:blank"
     
         strHTML = Html("-21.0207796666667", "55.2382640555556")
        DoEvents
    End Sub
    Et voila ce que j'obtiens: Capture 1

    Puis après avoir dit OK : capture 2
    Pourriez vous m'aider à régler ce problème ???? sachant que le fichier HTML associe s'affiche si j'utilise internet explorer directement avec par contre une demande d'autorisation du contenu bloque
    Images attachées Images attachées   

  19. #19
    Membre confirmé
    Homme Profil pro
    AutoEntrepreneur Photo
    Inscrit en
    Avril 2015
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : AutoEntrepreneur Photo
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2015
    Messages : 141
    Par défaut
    Bonjour,

    Pour ma part, je me suis arrêté au même problème que vous en concluant qu'on ne pouvait pas trop en demander au web browser...
    Si tu trouves je suis preneur !

  20. #20
    Membre confirmé
    Homme Profil pro
    AutoEntrepreneur Photo
    Inscrit en
    Avril 2015
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : AutoEntrepreneur Photo
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2015
    Messages : 141
    Par défaut
    PS: un bout de piste que j'avais commencé à fouiller à l'époque était de configurer les options de sécurité de windows/internet explorer, pour autoriser l'utilisation des scripts....
    Malheureusement, malgré ce que j'avais trouvé sur le net (qui marchait chez les autres), ça n'a pas marché chez moi....

Discussions similaires

  1. Web Browser flux page Html
    Par azstar dans le forum C#
    Réponses: 1
    Dernier message: 30/05/2011, 16h34
  2. web browser en java .. quel composant ?
    Par vdavid1982 dans le forum Composants
    Réponses: 3
    Dernier message: 22/10/2009, 16h08
  3. [web] lien HTML à partir de perl
    Par lilou0210 dans le forum Web
    Réponses: 4
    Dernier message: 05/11/2004, 00h16
  4. Cherche composant Web Browser indépendant
    Par lancelot69 dans le forum Composants VCL
    Réponses: 2
    Dernier message: 31/07/2002, 11h14

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo