Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Mark Your Map Location

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBWin Mark Your Map Location

    Based on work done by:
    Henk Spoelstra, Dean Goodman, José Roca, Gary Beene
    See here.

    Designed to work with PBWIN10 and Jose' includes.

    How to use this program.
    To get an updated location you can:
    1. Grab and move the map. The screen center info will be changed as you move the map.
    2. Click on any of the screen buttons.
    3. Click on the map. All markers will be erased and a new marker will be added at your click location.
    Once you have placed a marker on the map you will notice the map will pan so that your point is in the center of the map.
    The marker property can be seen by pointing at the marker. The property is the Latitude and Longitude of the marker location.

    NOTE:
    If you desire to save the location you must press Set Center.

    Have fun!


    Code:
    ' Grab Google Maps Center Map Coordinates Version 2
    
    ' I would like to thank these folks for their help in making this possible.
    ' Henk Spoelstra, Dean Goodman, José Roca, Gary Beene
    
    ' By: Jim Fritts on 03 DEC 2017 to provide map center Latitude and Longitude.
    ' The initial location is John Glenn International Airport
    ' It is plugged in here:
    '  C_Lat=
    '  C_Lng=
    
    ' How to use this program.
    '  To get an updated location you can:
    '   1. Grab and move the map. The screen center info will be changed as you move the map.
    '   2. Click on any of the screen buttons.
    '   3. Click on the map. All markers will be erased and a new marker will be added at your click location.
    '  Once you have placed a marker on the map you will notice the map will pan so that your point is in the center of the map.
    '  The marker property can be seen by pointing at the marker. The property is the Lat and Lon of the marker location.
    'NOTE:////////////////////////////////////////////////////////////////////
    '////  If you desire to save the location you must press Set Center.  ////
    '/////////////////////////////////////////////////////////////////////////
    
    'https://forum.powerbasic.com/forum/user-to-user-discussions/source-code/753199-grab-google-maps-corner-coordinates-and-image
    
    #COMPILE EXE
    #DIM ALL
    %UNICODE = 1
    %USEWEBBROWSER = 1
    %USEOLECON = 1                ' // Use the OLE container
    
    #INCLUDE ONCE "CWindow.inc"   ' // CWindow class
    #INCLUDE ONCE "MSHTML.INC"    ' // MSHTML
    
    %IDC_WEBBROWSER           = 1001    'Handle for the Webbrowser with the Google Map
    %IDC_CapImg               = 1002    'Handle for the window with the Google map image
    %ID_TEXTBOX1              = 3000
    
    %ID_WhichScript = 1
    
    
    FUNCTION PBMAIN
    
    ' // Create an instance of the class
    GLOBAL pWindow AS IWindow
    
      pWindow = CLASS "CWindow"
    IF ISNOTHING(pWindow) THEN EXIT FUNCTION
    
    ' // Initialize lat/lon as center point for the map
    LOCAL C_Lng, C_Lat AS DOUBLE                    'Center coordinates for the initial Google Map
    LOCAL Zoom AS LONG                             'Zoom for the initial Google Map
    
      'start location copy
      'John Glenn International Airport
      'LAT  39.99820898564898
      'LON -82.88432538514905
    
    C_Lat= 39.99820898564898
      C_Lng= -82.88432538514905
    
      Zoom = 15                                        'Zoom is set to max Set amount of zoom of the Google Map
    
      ' // Set size of DIALOG, Browser and Google map
    LOCAL   xSzDlg  , ySzDlg   AS LONG             'Width and height of the Dialog window
    GLOBAL  xSzMap  , ySzMap   AS LONG             'x-size (width) and y-size (height)of the map in the browser window (is needed in the Javascript and in the SUB Process_GoogleMap)
      'original size
    xSzDlg=310: ySzDlg=400                         'Set the x-size (width) and y-size (height) of the Dialog window
    xSzMap  = xSzDlg - 10                          'Calculate x-size (width)  of the map in the Browser window. Is used in the Javascript
    ySzMap  = ySzDlg - 100                         'Calculate y-size (height) of the map in the Browser window. Is used in the Javascript
    
      ' // Design of the Javascript code for retrieving the Google Map Corner Coordinates
    DIM s AS WSTRING
    
    s = "<!DOCTYPE html>"           'HTML5
    s +="<html>"
    s +="<head>"
    s += "      <meta http-equiv='X-UA-Compatible' content='IE=edge'>"   '--> added: used Edge browser
    s += "      <meta http-equiv='MSThemeCompatible' content='Yes'>"     '--> added: allow visual styles
    s += "      <meta name='viewport' content='initial-scale=1.0, user-scalable=no'/>"  'This setting specifies that the map should be displayed full-screen
    s += "      <meta http-equiv='content-type' content='text/html; charset=UTF-8'/>"
    
    s += "<title>" & $CRLF
    s += "Google Maps JavaScript API v3 Example: Optimized Directions" & $CRLF
    s += "</title>" & $CRLF
    
    s += "<style>" & $CRLF
    s +=   "/* Always set the map height explicitly to define the size of the div" & $CRLF
    s +=   "* element that contains the map. */" & $CRLF
    s +=   "#map {" & $CRLF
    s +=         "height: 100%;" & $CRLF
    s +=         "}" & $CRLF
    s +=   "/* Optional: Makes the sample page fill the window. */" & $CRLF
    s +=   "html, body {" & $CRLF
    s +=               "height: 100%;" & $CRLF
    s +=               "margin: 0;" & $CRLF
    s +=               "padding: 0;" & $CRLF
    s +=               "}" & $CRLF
    s +=   "#goCenterUI, #setCenterUI {" & $CRLF
    s +=                              "background-color: #fff;" & $CRLF
    s +=                              "border: 2px solid #fff;" & $CRLF
    s +=                              "border-radius: 3px;" & $CRLF
    s +=                              "box-shadow: 0 2px 6px rgba(0,0,0,.3);" & $CRLF
    s +=                              "cursor: pointer;" & $CRLF
    s +=                              "float: left;" & $CRLF
    s +=                              "margin-bottom: 22px;" & $CRLF
    s +=                              "text-align: center;" & $CRLF
    s +=                              "}" & $CRLF
    s +=   "#goCenterText, #setCenterText {" & $CRLF
    s +=                                  "color: rgb(25,25,25);" & $CRLF
    s +=                                  "font-family: Roboto,Arial,sans-serif;" & $CRLF
    s +=                                  "font-size: 15px;" & $CRLF
    s +=                                  "line-height: 25px;" & $CRLF
    s +=                                  "padding-left: 5px;" & $CRLF
    s +=                                  "padding-right: 5px;" & $CRLF
    s +=                                  "}" & $CRLF
    s +=   "#setCenterUI {" & $CRLF
    s +=                 "margin-left: 12px;" & $CRLF
    s +=                 "}" & $CRLF
    s += "</style>" & $CRLF
    s += "</head>"& $CRLF
    
    'Body starts here
    s += "<body>" & $CRLF
    s += "<div id = 'map' style='width: 297px; height: 295px; margin: 0; padding: 0; float:left; border: 1px solid black;'>" & $CRLF
    s += "</div>" & $CRLF
    
    'start of scripts
    s += "<script async defer"& $CRLF                    'type='text/javascript'
    s += "src='http://maps.google.com/maps/api/js?sensor=false&key=AIzaSyCOfu3Th4jwW6iR3Zw-Rzyx36uW7tGSu0c&libraries=places&callback=initMap'>" & $CRLF
    s += "</script>"& $CRLF
    
    s += "<script>" & $CRLF
    s += "/**" & $CRLF
    s += "* The CenterControl adds a control to the map that recenters the map on" & $CRLF
    s += "* initial position." & $CRLF
    s += "* @constructor" & $CRLF
    s += "* @param {!Element} controlDiv" & $CRLF
    s += "* @param {!google.maps.Map} map" & $CRLF
    s += "* @param {?google.maps.LatLng} center" & $CRLF
    s += "*/" & $CRLF
    s += "function CenterControl(controlDiv, map, center) {" & $CRLF
    s +=   "// We set up a variable for this since we're adding event listeners" & $CRLF
    s +=   "// later." & $CRLF
    s +=   "var control = this;" & $CRLF
    
    s +=   "// Set the center property upon construction" & $CRLF
    s +=   "control.center_ = center;" & $CRLF
    s +=   "controlDiv.style.clear = 'both';" & $CRLF
    
    s +=   "// Set CSS for the control border" & $CRLF
    s +=   "var goCenterUI = document.createElement('div');" & $CRLF
    s +=   "goCenterUI.id = 'goCenterUI';" & $CRLF
    s +=   "goCenterUI.title = 'Click to recenter the map';" & $CRLF
    s +=   "controlDiv.appendChild(goCenterUI);" & $CRLF
    
    s +=   "// Set CSS for the control interior" & $CRLF
    s +=   "var goCenterText = document.createElement('div');" & $CRLF
    s +=   "goCenterText.id = 'goCenterText';" & $CRLF
    s +=   "goCenterText.innerHTML = 'Center Map';" & $CRLF
    s +=   "goCenterUI.appendChild(goCenterText);" & $CRLF
    
    s +=   "// Set CSS for the setCenter control border" & $CRLF
    s +=   "var setCenterUI = document.createElement('div');" & $CRLF
    s +=   "setCenterUI.id = 'setCenterUI';" & $CRLF
    s +=   "setCenterUI.title = 'Click to change the center of the map';" & $CRLF
    s +=   "controlDiv.appendChild(setCenterUI);" & $CRLF
    
    s +=   "// Set CSS for the control interior" & $CRLF
    s +=   "var setCenterText = document.createElement('div');" & $CRLF
    s +=   "setCenterText.id = 'setCenterText';" & $CRLF
    s +=   "setCenterText.innerHTML = 'Set Center';" & $CRLF
    s +=   "setCenterUI.appendChild(setCenterText);" & $CRLF
    
    s +=   "// Set up the click event listener for 'Center Map': Set the center of" & $CRLF
    s +=   "// the map" & $CRLF
    s +=   "// to the current center of the control." & $CRLF
    s +=   "goCenterUI.addEventListener('click', function() {" & $CRLF
    s +=                                                    "var currentCenter = control.getCenter();" & $CRLF
    s +=                                                    "map.setCenter(currentCenter);" & $CRLF
    s +=                                                    "});" & $CRLF
    
    s +=   "// Set up the click event listener for 'Set Center': Set the center of" & $CRLF
    s +=   "// the control to the current center of the map." & $CRLF
    s +=   "setCenterUI.addEventListener('click', function() {" & $CRLF
    s +=                                                     "var newCenter = map.getCenter();" & $CRLF
    s +=                                                     "control.setCenter(newCenter);" & $CRLF
    s +=                                                     "});" & $CRLF
    s += "}" & $CRLF
    
    s += "/**" & $CRLF
    s += "* Define a property to hold the center state." & $CRLF
    s += "* @private" & $CRLF
    s += "*/" & $CRLF
    s += "CenterControl.prototype.center_ = null;" & $CRLF
    
    s += "/**" & $CRLF
    s += "* Gets the map center." & $CRLF
    s += "* @return {?google.maps.LatLng}" & $CRLF
    s += "*/" & $CRLF
    s += "CenterControl.prototype.getCenter = function() {" & $CRLF
    s +=                                                 "return this.center_;" & $CRLF
    s +=                                                 "};" & $CRLF
    
    s += "/**" & $CRLF
    s += "* Sets the map center." & $CRLF
    s += "* @param {?google.maps.LatLng} center" & $CRLF
    s += "*/" & $CRLF
    s += "CenterControl.prototype.setCenter = function(center) {" & $CRLF
    s +=                                                       "this.center_ = center;" & $CRLF
    s +=                                                       "};" & $CRLF
    
    s += "// Deletes all markers in the array by removing references to them." & $CRLF
    s += "function DeleteMarkers() {" & $CRLF
    s += "//Loop through all the markers and remove" & $CRLF
    s += "for (var i = 0; i < markers.length; i++) {" & $CRLF
    s += "  markers[i].setMap(null);" & $CRLF
    s += "}" & $CRLF
    s += "markers = [];" & $CRLF
    s += "};" & $CRLF
    
    s +=  "var map;"& $CRLF
    s +=  "var markers = [];" & $CRLF
    s +=  "var location;"& $CRLF
    
    'initialization function
    s += "function initMap()" & $CRLF
    s += "{"& $CRLF
    s +=    "var location = new google.maps.LatLng(" & FORMAT$(C_Lat) & " , " & FORMAT$(C_Lng) & ")" & $CRLF
    s +=    "var myOptions = {"& $CRLF
    s +=                     "center: location," & $CRLF
    s +=                     "zoom:"& LTRIM$(STR$(Zoom)) & "," & $CRLF
    s +=                     "mapTypeId:google.maps.MapTypeId.SATELLITE," & $CRLF
    s +=                     "mapTypeControl: true,"& $CRLF
    s +=                     "mapTypeControlOptions: {"& $CRLF
    s +=                            "style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,"& $CRLF
    s +=                            "position: google.maps.ControlPosition.LEFT_BOTTOM"& $CRLF   'BOTTOM_CENTER
    s +=                            "},"& $CRLF
    s +=                     "zoomControl: true,"& $CRLF
    s +=                     "zoomControlOptions: {"& $CRLF
    s +=                         "position: google.maps.ControlPosition.RIGHT_BOTTOM"& $CRLF
    s +=                         "},"& $CRLF
    s +=                     "scaleControl: true,"& $CRLF
    s +=                     "streetViewControl: false,"& $CRLF
    s +=                     "streetViewControlOptions: {"& $CRLF
    s +=                               "position: google.maps.ControlPosition.RIGHT_BOTTOM"& $CRLF
    s +=                               "},"& $CRLF
    s +=                     "fullscreenControl: false"& $CRLF
    s +=                     "};"& $CRLF
    
    s +=    "directionsDisplay = new google.maps.DirectionsRenderer();" & $CRLF
    s +=    "var store = new google.maps.LatLng(" & FORMAT$(C_Lat) & "," & FORMAT$(C_Lng) & ");" & $CRLF
    s +=    "map = new google.maps.Map(document.getElementById('map'), myOptions);" & $CRLF
    
    s +=    "// This event listener will update data when map center has changed." & $CRLF
    s +=    "map.addListener('center_changed', function() " & $CRLF
    s +=    "{" & $CRLF
    s +=      "var id_bounds = map.getBounds();"  & $CRLF
    s +=      "var id_ne = id_bounds.getNorthEast();"& $CRLF  ' LatLng of the north-east corner    'northeast
    s +=      "var id_sw = id_bounds.getSouthWest();"& $CRLF  ' LatLng of the south-west corder    'southwest
    s +=      "var id_zm = map.getZoom();"& $CRLF             ' Get the actual zoom
    s +=      "var id_cn = map.getCenter();"& $CRLF           ' LatLng of the map center
    
    s +=      "document.getElementById('ne').value = id_ne;"& $CRLF
    s +=      "document.getElementById('sw').value = id_sw;"& $CRLF
    s +=      "document.getElementById('zm').value = id_zm;"& $CRLF
    s +=      "document.getElementById('cn').value = id_cn;"& $CRLF
    
    s +=      "document.getElementById('ne_coord').value = id_ne;"& $CRLF
    s +=      "document.getElementById('sw_coord').value = id_sw;"& $CRLF
    s +=      "document.getElementById('zoom').value = id_zm;"& $CRLF
    s +=      "document.getElementById('cn_coord').value = id_cn;"& $CRLF
    s +=    "});" & $CRLF
    
    s +=    "// This event listener will update data when map has finished panning or changing zoom." & $CRLF
    s +=    "map.addListener('idle', function() " & $CRLF
    s +=    "{" & $CRLF
    s +=      "var id_bounds = map.getBounds();"  & $CRLF
    s +=      "var id_ne = id_bounds.getNorthEast();"& $CRLF  ' LatLng of the north-east corner    'northeast
    s +=      "var id_sw = id_bounds.getSouthWest();"& $CRLF  ' LatLng of the south-west corder    'southwest
    s +=      "var id_zm = map.getZoom();"& $CRLF             ' Get the actual zoom
    s +=      "var id_cn = map.getCenter();"& $CRLF           ' LatLng of the map center
    
    s +=      "document.getElementById('ne').value = id_ne;"& $CRLF
    s +=      "document.getElementById('sw').value = id_sw;"& $CRLF
    s +=      "document.getElementById('zm').value = id_zm;"& $CRLF
    s +=      "document.getElementById('cn').value = id_cn;"& $CRLF
    
    s +=      "document.getElementById('ne_coord').value = id_ne;"& $CRLF
    s +=      "document.getElementById('sw_coord').value = id_sw;"& $CRLF
    s +=      "document.getElementById('zoom').value = id_zm;"& $CRLF
    s +=      "document.getElementById('cn_coord').value = id_cn;"& $CRLF
    s +=    "});" & $CRLF
    
    s +=    "// This event listener will call addMarkerX() when the map is clicked." & $CRLF
    s +=    "map.addListener('click', function(event) " & $CRLF
    s +=    "{" & $CRLF
    s +=      "addMarkerX(event.latLng);" & $CRLF
    s +=    "});" & $CRLF
    
    s +=    "// Places an initial marker at the center of the map." & $CRLF
    s +=    "addMarkerX(location);" & $CRLF
    
    s +=    "// Create the DIV to hold the control and call the CenterControl()" & $CRLF
    s +=    "// constructor" & $CRLF
    s +=    "// passing in this DIV." & $CRLF
    s +=    "var centerControlDiv = document.createElement('div');" & $CRLF
    s +=    "var centerControl = new CenterControl(centerControlDiv, map, location);" & $CRLF
    
    s +=    " centerControlDiv.index = 1;" & $CRLF
    s +=    "centerControlDiv.style['padding-top'] = '10px';" & $CRLF
    s +=    " map.controls[google.maps.ControlPosition.TOP_CENTER].push(centerControlDiv);" & $CRLF
    
    s += "}" & $CRLF 'this does not look right where is the (& $crlf)
    
    s +=   "var Temp;" & $CRLF
    s += "// Adds a marker to the map and push to the array." & $CRLF
    'addMarkerX function
    s += "function addMarkerX(location)" & $CRLF
    s += "{" & $CRLF
    s +=   "Temp = location," & $CRLF
    s +=   "DeleteMarkers()," & $CRLF
    s +=   "addMarker(Temp)" & $CRLF
    s += "}" & $CRLF
    
    s += "// Adds a marker to the map and push to the array." & $CRLF
    'addMarker function
    s += "function addMarker(location)" & $CRLF
    s += "{" & $CRLF
    s +=   "var marker = new google.maps.Marker({" & $CRLF
    s +=                                        "position: location," & $CRLF
    s +=                                        "map: map," & $CRLF
    s +=                                        "title: location.toString()" & $CRLF   ''Click to zoom'
    s +=                                        "});" & $CRLF
    s +=   "markers.push(marker);" & $CRLF
    s +=   "map.panTo(location);" & $CRLF
    s +=   "store = location;" & $CRLF
    s += "}" & $CRLF
    
    s += "google.maps.event.addDomListener(window, 'load', initMap); "& $CRLF
    s += "</script>"& $CRLF
    
    '  s += "</script>" & $CRLF
    
    s += "<br>"& $CRLF
    s += "<input type='hidden' id='ne' name='ne' size='38' value='ne'>"& $CRLF   'https://www.experts-exchange.com/questions/28499086/Visual-Studio-2013-Get-latitude-Longitude-from-google-Map-in-windows-project.html#answer40294233
    s += "<input type='hidden' id='sw' name='sw' size='38' value='sw'>"& $CRLF
    s += "<input type='hidden' id='zm' name='zm' size='38' value='zm'>"& $CRLF
    s += "<input type='hidden' id='cn' name='cn' size='38' value='cn'>"& $CRLF
    s += "<input type='hidden' id='Grab coordinates' name='button' value='Grab coordinates' onclick='getCorners()'>"& $CRLF    'MUST BE ONCLICK AS IN THE "CLASS CHTMLDocumentEvents2" THE METHOD is defined as ONCLICK !!!
    
    s += "<input type='hidden'   id='ne_coord' name='ne_result' size='75' value='ne-coordinates'>"& $CRLF
    s += "<input type='hidden'   id='sw_coord' name='sw_result' size='75' value='sw-coordinates'>"& $CRLF
    s += "<input type='hidden'   id='zoom'     name='zm'        size='20' value='zoom'>"& $CRLF
    s += "<input type='hidden'   id='cn_coord' name='cn' size='75' value='cn-coordinates'>"& $CRLF
    s += "</br>"& $CRLF
    
    s += "</body> "& $CRLF
    
    s +="</html> "& $CRLF
    
    
    
    ' // Save the Javascript as a temporary file
    LOCAL bstrTempFileName   AS WSTRING
    bstrTempFileName = AfxSaveTempFile(s, "", "TMP", "html", 1)
    
    ' // Set the CLASS for capturing EVENTS in the Webbrowser
    LOCAL pWBEvents      AS DWebBrowserEvents2Impl
      pWBEvents = CLASS "CDWebBrowserEvents2"
    
    ' // Create the Dialog/WebBrowser control with the embedded map
    GLOBAL hDlg  AS DWORD               'Reference to Dialog window (which is the webbrowser window)
    DIALOG NEW PIXELS, 0, "Map Location Selection", , , xSzDlg, ySzDlg, %WS_OVERLAPPEDWINDOW TO hDlg               'Make Dialog window
    pWindow.AddWebBrowserControl(hDlg, %IDC_WEBBROWSER, bstrTempFileName, pWBEvents, 5, 5, xSzMap, ySzMap)    'AddWebBrowserControl is a METHOD defined in CWindow.INC
    
    CONTROL ADD TEXTBOX, hDlg, %ID_TEXTBOX1, "", 5, 315, 300, 60, %ES_CENTER OR %ES_MULTILINE
    
    
    'pWBEvents is a call to the Events
      '// Show Dialog and start the Callback Processor
    DIALOG SHOW MODAL hDlg, CALL DlgProc
    
    END FUNCTION
    
    
    ' ========================================================================================
    ' Main Dialog CALLBACK procedure
    ' ========================================================================================
    CALLBACK FUNCTION DlgProc() AS LONG
    
    SELECT CASE CB.MSG
        CASE %WM_INITDIALOG
            DIALOG ENABLE hDlg
    
    CASE %WM_COMMAND
            SELECT CASE AS LONG CB.CTL
    'CASE %IDC_BUTTON
              '    IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
              '
              '    END IF
    END SELECT
    
        CASE %WM_SIZE
            IF CB.WPARAM <> %SIZE_MINIMIZED THEN
    '
            ' When RESIZING the browser window. The Google Map size stays the same.
            ' If the Google Map need to be resized as well then teh Javascript must be run again.
            '
    
    END IF
    
        CASE %WM_DESTROY
    hdlg=0
    END SELECT
    
    END FUNCTION
    
    
    ' ########################################################################################
    ' Class CDWebBrowserEvents2
    ' Interface name = DWebBrowserEvents2
    ' IID = {34A715A0-6587-11D0-924A-0020AFC7AC4D}
    ' Web Browser Control events interface
    ' Attributes = 4112 [&H1010] [Hidden] [Dispatchable]
    ' ########################################################################################
    
    CLASS CDWebBrowserEvents2 GUID$("{700B73A2-CCFC-4FE0-B9AC-D5853D71B7B9}") AS EVENT
    
       INSTANCE pIWebBrowser2 AS IWebBrowser2
    INSTANCE pHTMLDocumentEvents2 AS HTMLDocumentEvents2Impl
    
    ' =====================================================================================
    CLASS METHOD DESTROY
    ' Disconnect events
    IF ISOBJECT(pHTMLDocumentEvents2) THEN EVENTS END pHTMLDocumentEvents2
    END METHOD
    ' =====================================================================================
    
    ' ========================================================================================
    ' Implementation of the interface
    ' ========================================================================================
    INTERFACE DWebBrowserEvents2Impl GUID$("{34A715A0-6587-11D0-924A-0020AFC7AC4D}") AS EVENT
    
      INHERIT IDISPATCH
    
    ' =====================================================================================
       ' Note (October 2, 2016):
       ' The METHOD DocumentComplete has been placed here as the original METHOD DownloadComplete
       ' fires three times. See:
       ' https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/753161-addwebbrowsercontrol-fires-three-times-with-pwbevents
       ' However the DocumentComplete does not fire when the Webbrowser is not visible.
       ' See: BUG: DocumentComplete Does Not Fire When WebBrowser Is Not Visible
       ' http://support.microsoft.com/kb/q259935/
       ' =====================================================================================
    METHOD DocumentComplete <259> ( _
         BYVAL pDisp AS IDISPATCH _                         ' __in IDispatch* pDisp
    , BYREF vURL AS VARIANT _                            ' __in VARIANT* URL
    )                                                    ' void
    
          ' Get a reference to the IHTMLDocument2 interface
    LOCAL pHTMLDocument2 AS IHTMLDocument2
          pHTMLDocument2 = pIWebBrowser2.Document
    IF ISNOTHING(pHTMLDocument2) THEN EXIT METHOD
    
    ' Connect to the events fired by the page
    pHTMLDocumentEvents2 = CLASS "CHTMLDocumentEvents2"
    IF ISNOTHING(pHTMLDocumentEvents2) THEN EXIT METHOD
          EVENTS FROM pHTMLDocument2 CALL pHTMLDocumentEvents2
    
    END METHOD
    ' =====================================================================================
    
       ' =====================================================================================
    METHOD BeforeNavigate2 <250> ( _
         BYVAL pDisp AS IDISPATCH _                         ' __in IDispatch* pDisp
    , BYREF vURL AS VARIANT _                            ' __in VARIANT* URL
    , BYREF vFlags AS VARIANT _                          ' __in VARIANT* Flags
    , BYREF vTargetFrameName AS VARIANT _                ' __in VARIANT* TargetFrameName
    , BYREF vPostData AS VARIANT _                       ' __in VARIANT* PostData
    , BYREF vHeaders AS VARIANT _                        ' __in VARIANT* Headers
    , BYREF bCancel AS INTEGER _                         ' __in_out VARIANT_BOOL* Cancel
    )                                                    ' void
    
          ' Get a reference to the WebBrowser control
    IF ISNOTHING(pIWebBrowser2) THEN pIWebBrowser2 = pDisp
    IF ISNOTHING(pIWebBrowser2) THEN EXIT METHOD
    ' If there was a previous loaded page, disconnect from the events
    IF ISOBJECT(pHTMLDocumentEvents2) THEN
             EVENTS END pHTMLDocumentEvents2
             pHTMLDocumentEvents2 = NOTHING
          END IF
    
       END METHOD
    ' =====================================================================================
    
    END INTERFACE
    
    END CLASS
    ' ########################################################################################
    
    
    ' ########################################################################################
    ' Class CHTMLDocumentEvents2
    ' Interface name = HTMLDocumentEvents2
    ' IID = {3050F613-98B5-11CF-BB82-00AA00BDCE0B}
    ' Attributes = 4112 [&H1010] [Hidden] [Dispatchable]
    ' ########################################################################################
    
    CLASS CHTMLDocumentEvents2 GUID$("{1FFB0071-8BCC-4BBD-BC29-A662FAE87C82}") AS EVENT
    
    INTERFACE HTMLDocumentEvents2Impl GUID$("{3050F613-98B5-11CF-BB82-00AA00BDCE0B}") AS EVENT
    
      INHERIT IDISPATCH
    
    ' =====================================================================================
    METHOD onclick <-600> ( _
         BYVAL pEvtObj AS IHTMLEventObj _                   ' __in IHTMLEventObj* pEvtObj
    )                                                    ' void
          '? "Made it here"
    LOCAL pElement AS IHTMLElement           ' // Element that has fired the event
    LOCAL pHTMLDocument2 AS IHTMLDocument2   ' // Document object
    LOCAL bstrId AS WSTRING                  ' // Identifier of the element that has fired the event
    LOCAL bstrValue AS WSTRING               ' // Value of the property
    
          ' // Get a reference to the element that has fired the event
    IF ISOBJECT(pEvtObj) THEN pElement = pEvtObj.srcElement
    IF ISNOTHING(pElement) THEN EXIT METHOD
    
    ' // Get a reference to the IHTMLDocument2 interface
    pHTMLDocument2 = pElement.document
    IF ISNOTHING(pHTMLDocument2) THEN EXIT METHOD
    
    ' // Get the identifier of the element that has fired the event
    bstrId = pElement.id
    
    LOCAL CN_Coord_STR     AS STRING                  'Grabbed Center Coordinates as string
    
          '? "you clicked on the screen so display location"
    bstrValue = IHTMLDocument_getElementValueById(pHTMLDocument2, "cn_coord")
    CN_Coord_STR=bstrValue
    CALL Display_GoogleMap_LatLon(CN_Coord_STR)
    
    END METHOD
    ' =====================================================================================
    
    END INTERFACE
    
    END CLASS
    ' ########################################################################################
    
    
    
    '---------------- SUB Display_GoogleMap_LatLon
    SUB Display_GoogleMap_LatLon(BYVAL CN_Coord_STR AS STRING)
    LOCAL CN_LatStr, CN_LngStr AS STRING
      LOCAL CN_Lat, CN_lng AS DOUBLE
    
    CN_LatStr = PARSE$(CN_Coord_STR, ",", 1)   'Take the left portion up to the comma
    REPLACE "(" WITH "" IN CN_LatStr
      CN_LngStr = PARSE$(CN_Coord_STR, ",", 2)   'Take the right portion from the comma to the end
    REPLACE ")" WITH "" IN CN_LngStr
    
      CN_Lat    = VAL(CN_LatStr)
    CN_Lng    = VAL(CN_LngStr)
    
    CONTROL SET TEXT hDlg, %ID_TEXTBOX1, "Map Center Latitude & Longitude:" + $CRLF + $CRLF + FORMAT$(CN_Lat, "###.##############") + ", " + _
        FORMAT$(CN_Lng, "###.##############")
    END SUB


Working...
X