Jump to content

Google Maps UDF


 Share

Recommended Posts

This UDF allows users to create and manipulate Google Map and Google Earth controls within an AutoIT GUI.

This UDF currently implements functions from:

  • Google Maps Javascript API Version 3
  • Google Earth API Version 1
REQUIREMENTS:

LIST OF FUNCTIONS:

_GUICtrlGoogleMap_GetLatLng($address)

_GUICtrlGoogleMap_Create(ByRef $gmap, $left, $top, $width, $height, $address, $zoom = 8, $marker = True, $map_type = 0, $navigation_style = 0, $scale_style = 0, $map_type_style = 0)

_GUICtrlGoogleMap_SetView($gmap, $address)

_GUICtrlGoogleMap_ZoomView($gmap, $scale)

_GUICtrlGoogleMap_AddMarker($gmap, $address, $icon_url = "")

_GUICtrlGoogleMap_HideAllMarkers($gmap)

_GUICtrlGoogleMap_ShowAllMarkers($gmap)

_GUICtrlGoogleMap_DeleteAllMarkers($gmap)

_GUICtrlGoogleMap_ViewAllMarkers($gmap)

_GUICtrlGoogleMap_SetMapType($gmap, $map_type)

_GUICtrlGoogleMap_AddRoute($gmap, $start_location, $end_location, $travel_mode = 0)

_GUICtrlGoogleMap_GetRoute($gmap, $start_location, $end_location, ByRef $distance, ByRef $duration, $travel_mode = 0)

_GUICtrlGoogleEarth_Create(ByRef $ge, $gmap_api_key, $left, $top, $width, $height, $address, $zoom = 10000, $fly_to_speed = "ge.SPEED_TELEPORT")

EXAMPLE:

Google Maps Example

The following example demonstrates how the Google Maps UDF can be used to create an embedded Google Map in an AutoIT GUI. It allows the user to:

  • pan the view to a new location
  • zoom to different levels
  • add markers to different locations on the map (using different icons)
  • make all markers hidden, shown, deleted, or panned into view
  • hide and show the map itself
  • change the map type
  • add (render) a route between two locations
  • get the details of a route (navigation instructions, distances and durations)
When the GUI first opens, the location "Palm Beach, Queensland, Australia" is displayed. A series of tabs exist at the bottom where similar controls are grouped together. The user may type a latitude and longitude, or an address, within the Set View To, Add Marker To input controls. For example, both "Sydney, New South Wales, Australia" and "-34.397, 150.644" would be valid.

Whilst View All Markers after Add is checked, everytime Add Marker To is clicked the map's view will be adjusted to include all markers, including the one just added.

Also note the following:

  • the GUI itself is resizable and maximizable, and resizing it will also resize the map
  • whilst the cursor is within in the input fields (Set View to, Zoom view to and Add Marker to) the Enter key will trigger the associated button
  • The Route Info button may need to be clicked more than once to return a result. Unknown at this stage what is wrong.
Google Maps Example.au3

Google Earth Example

The following example demonstrates how the Google Maps UDF can be used to create an embedded Google Earth in an AutoIT GUI.

When the GUI first opens, the location "Palm Beach, Queensland, Australia" is displayed. The user may use their mouse and keyboard, in the same manner as in Google Earth, to pan and zoom around the Earth.

The GUI itself is resizable and maximizable, and resizing it will also resize the Earth.

Note that there are two prerequisites that you must complete prior to running this example successfully:

  • The Google Earth Plug-in must be installed in your Internet Explorer browser. To install the plugin, using Internet Explorer visit http://code.google.com/apis/earth and follow the instructions provided.
  • A Google Maps API key is also required for this example to work. You must obtain your own personal key from Google, and pass it into this example for it to work. To obtain a key, visit http://code.google.com/apis/maps/signup.html, and when prompted for your web site URL, supply the URL of "http://localhost". You will also be asked to sign in with your Google Account details.
Google Earth Example.au3

DOWNLOAD:

Latest Version - v0.4 (10/06/10)

Google Maps.au3

Edited by seangriffin

Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia
Link to comment
Share on other sites

@seangriffin

Nice app I agree. :mellow:

But I would suggest to make the GUI resizable.

Rgds

ptrex

Thanks ptrex.

Updated the example to include:

  • a resizable GUI
  • default button handling for the input fields, such that users can simply press Enter when inside input fields to apply them
  • a checkbox to automatically view all markers after each marker is added to the map
Yeah looks real schmick now. Edited by seangriffin

Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia
Link to comment
Share on other sites

Great job. I really like it. There is a lot google APIs that can be taken advantage of just like this to make some really cool and useful programs. 5 stars from me.

Edited by dantay9
Link to comment
Share on other sites

Whenever I try to add a marker to my chosen location the map zooms all of the way out. I guess this is a bug. The first version didn't do that.

Edit: nvm, lulz, my bad, it isn't a bug, duh!

Edited by jaberwocky6669
Link to comment
Share on other sites

Here is my AutoItObject version. You no longer have to declare $gmap in the example. Nor do you have to pass it into any of the functions!

"Google Maps.au3"

#include-once

#include "AutoItObject.au3"
#include <GUIConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <IE.au3>

#region Header
#cs
    Title:      Google Maps UDF Library for AutoIt3
    Filename:       Google Maps.au3
    Description:    A collection of functions for creating and controlling a Google Maps control in AutoIT
    Author:         seangriffin
    Version:        V0.1
    Last Update:    06/06/10
    Requirements:   AutoIt3 3.2 or higher
    Changelog:      ---------06/06/10---------- v0.1
    Initial release.

#ce
#endregion Header

#region Global Variables and Constants
#endregion Global Variables and Constants

#region GoogleMap Object
Func GoogleMap()
    Local $this = _AutoItObject_Create()
    _AutoItObject_AddProperty($this, "gmap", $ELSCOPE_PRIVATE)
    _AutoItObject_AddMethod($this, "GetLatLng", "_GUICtrlGoogleMap_GetLatLng")
    _AutoItObject_AddMethod($this, "Create", "_GUICtrlGoogleMap_Create")
    _AutoItObject_AddMethod($this, "SetView", "_GUICtrlGoogleMap_SetView")
    _AutoItObject_AddMethod($this, "ZoomView", "_GUICtrlGoogleMap_ZoomView")
    _AutoItObject_AddMethod($this, "AddMarker", "_GUICtrlGoogleMap_AddMarker")
    _AutoItObject_AddMethod($this, "HideAllMarkers", "_GUICtrlGoogleMap_HideAllMarkers")
    _AutoItObject_AddMethod($this, "ShowAllMarkers", "_GUICtrlGoogleMap_ShowAllMarkers")
    _AutoItObject_AddMethod($this, "DeleteAllMarkers", "_GUICtrlGoogleMap_DeleteAllMarkers")
    _AutoItObject_AddMethod($this, "ViewAllMarkers", "_GUICtrlGoogleMap_ViewAllMarkers")
    Return $this
EndFunc ;==>GoogleMap
#endregion GoogleMap Object

#region Core functions
; #FUNCTION# ;===============================================================================
;
; Name...........:  _GUICtrlGoogleMap_GetLatLng()
; Description ...:  Converts an address into a latitude and longitude array.
; Syntax.........:  _GUICtrlGoogleMap_GetLatLng($address)
; Parameters ....:  $address        - the address (either a location or latitude and longitude) to convert
;                    ie. both "Sydney, New South Wales, Australia" and "-34.397, 150.644" are valid.
; Return values .:  On Success      - Returns an array with the latitude and longitude of the address.
;       On Failure      - Returns False.
; Author ........:  seangriffin
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:  Yes
;
; ;==========================================================================================
Func _GUICtrlGoogleMap_GetLatLng($this, $address)
    Local $latlng[2]

    Local $address_part = StringSplit($address, ",", 2)

    ; if the geocode is a lat long
    If UBound($address_part) - 1 = 2 And IsNumber($address_part[0]) = True And IsNumber($address_part[1]) = True Then

        $latlng[0] = StringStripWS($address_part[0], 3)
        $latlng[1] = StringStripWS($address_part[1], 3)
    Else

        ; convert the address to a lat long
        Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
        $oHTTP.Open("GET", "http://maps.google.com/maps/api/geocode/json?address=" & $address & "&sensor=false")
        $oHTTP.Send()
        Local $HTMLSource = $oHTTP.Responsetext

        Local $geocode_line = StringSplit($HTMLSource, @LF, 1)

        $latlng[0] = $geocode_line[_ArraySearch($geocode_line, """lat"":", 0, 0, 1, 1)]
        $latlng[0] = StringStripWS(StringReplace(StringReplace($latlng[0], """lat"":", ""), ",", ""), 3)
        $latlng[1] = $geocode_line[_ArraySearch($geocode_line, """lng"":", 0, 0, 1, 1)]
        $latlng[1] = StringStripWS(StringReplace(StringReplace($latlng[1], """lng"":", ""), ",", ""), 3)
    EndIf

    Return $latlng
EndFunc ;==>_GUICtrlGoogleMap_GetLatLng

; #FUNCTION# ;===============================================================================
;
; Name...........:  _GUICtrlGoogleMap_Create()
; Description ...:  Creates a Google Map control.
; Syntax.........:  _GUICtrlGoogleMap_Create(ByRef $gmap, $left, $top, $width, $height, $geocode, $zoom = 8, $marker = True)
; Parameters ....:  $gmap           - The embedded Google Map object, required by the _GUICtrlGoogleMap functions below.
;                   $left           - The left side of the control.
;                   $top            - The top of the control.
;                   $width          - The width of the control.
;                   $height         - The height of the control.
;                   $address        - An address (either a location or latitude and longitude) to center the map on
;                    ie. both "Sydney, New South Wales, Australia" and "-34.397, 150.644" are valid.
;                   $zoom           - An initial map zoom level.
;                   $marker         - A boolean indicating whether a marker should be created for the above address.
; Return values .:  On Success      - Returns the identifier (controlID) of the new control.
;       On Failure      - Returns False.
; Author ........:  seangriffin
; Modified.......:
; Remarks .......:  This function must be used before any other function in the UDF is used.
; Related .......:
; Link ..........:
; Example .......:  Yes
;
; ;==========================================================================================
Func _GUICtrlGoogleMap_Create($this, $left, $top, $width, $height, $address, $zoom = 8, $marker = True)
    Local $latlng[2]

    $latlng = $this.GetLatLng($address)

    Local Const $html = _
            "<html>" & @CRLF & _
            "<head>" & @CRLF & _
            "<meta name=""viewport"" content=""initial-scale=1.0, user-scalable=no"" />" & @CRLF & _
            "<meta http-equiv=""content-type"" content=""text/html; charset=UTF-8""/>" & @CRLF & _
            "<script type=""text/javascript"" src=""http://maps.google.com/maps/api/js?sensor=false""></script>" & @CRLF & _
            "<script type=""text/javascript"">" & @CRLF & _
            " var map;" & @CRLF & _
            " var markersArray = [];" & @CRLF & _
            " function initialize() {" & @CRLF & _
            "   var latlng = new google.maps.LatLng(" & $latlng[0] & "," & $latlng[1] & ");" & @CRLF & _
            "   var myOptions = {" & @CRLF & _
            "   zoom: " & $zoom & "," & @CRLF & _
            "   center: latlng," & @CRLF & _
            "   mapTypeId: google.maps.MapTypeId.ROADMAP" & @CRLF & _
            "   };" & @CRLF & _
            "   map = new google.maps.Map(document.getElementById(""map_canvas""), myOptions);" & @CRLF & _
            "   if (" & StringLower($marker) & ") {" & @CRLF & _
            "   addMarker(" & $latlng[0] & "," & $latlng[1] & ");" & @CRLF & _
            "   }" & @CRLF & _
            " }" & @CRLF & _
            " function addMarker(lat, lng, icon_url) {" & @CRLF & _
            "   var location = new google.maps.LatLng(lat, lng);" & @CRLF & _
            "   marker = new google.maps.Marker({" & @CRLF & _
            "   position: location," & @CRLF & _
            "   map: map," & @CRLF & _
            "   icon: icon_url" & @CRLF & _
            "   });" & @CRLF & _
            "   markersArray.push(marker);" & @CRLF & _
            " }" & @CRLF & _
            " function clearMarkers() {" & @CRLF & _
            "   if (markersArray) {" & @CRLF & _
            "   for (i in markersArray) {" & @CRLF & _
            "   markersArray[i].setMap(null);" & @CRLF & _
            "   }" & @CRLF & _
            "   }" & @CRLF & _
            " }" & @CRLF & _
            " function showMarkers() {" & @CRLF & _
            "   if (markersArray) {" & @CRLF & _
            "   for (i in markersArray) {" & @CRLF & _
            "   markersArray[i].setMap(map);" & @CRLF & _
            "   }" & @CRLF & _
            "   }" & @CRLF & _
            " }" & @CRLF & _
            " function deleteMarkers() {" & @CRLF & _
            "   if (markersArray) {" & @CRLF & _
            "   for (i in markersArray) {" & @CRLF & _
            "   markersArray[i].setMap(null);" & @CRLF & _
            "   }" & @CRLF & _
            "   markersArray.length = 0;" & @CRLF & _
            "   }" & @CRLF & _
            " }" & @CRLF & _
            " function viewMarkers() {" & @CRLF & _
            "   if (markersArray) {" & @CRLF & _
            "   var latlngbounds = new google.maps.LatLngBounds();" & @CRLF & _
            "   for (i in markersArray) {" & @CRLF & _
            "   latlngbounds.extend(markersArray[i].getPosition());" & @CRLF & _
            "   }" & @CRLF & _
            "   map.fitBounds(latlngbounds);" & @CRLF & _
            "   }" & @CRLF & _
            " }" & @CRLF & _
            " function move_map(lat, lng) {" & @CRLF & _
            "   var latlng = new google.maps.LatLng(lat, lng);" & @CRLF & _
            "   map.setCenter(latlng);" & @CRLF & _
            " }" & @CRLF & _
            " function zoom_map(scale) {" & @CRLF & _
            "   map.setZoom(scale);" & @CRLF & _
            " }" & @CRLF & _
            "</script>" & @CRLF & _
            "</head>" & @CRLF & _
            "<body style=""margin:0px; padding:0px;"" onload=""initialize()"">" & @CRLF & _
            "<div id=""map_canvas"" style=""width:100%; height:100%""></div>" & @CRLF & _
            "</body>" & @CRLF & _
            "</html>"

    $this.gmap = _IECreateEmbedded()

    Local $gmap_ctrl = GUICtrlCreateObj($this.gmap, $left, $top, $width, $height)

    Local $gmap = $this.gmap

    _IENavigate($gmap, "about:blank")

    _IEDocWriteHTML($gmap, $html)

    $this.gmap.refresh()

    _IELoadWait($gmap)

    $this.gmap.document.body.scroll = "no"

    Return $gmap_ctrl
EndFunc ;==>_GUICtrlGoogleMap_Create

; #FUNCTION# ;===============================================================================
;
; Name...........:  _GUICtrlGoogleMap_SetView()
; Description ...:  Sets the center of a Google Map to a new address.
; Syntax.........:  _GUICtrlGoogleMap_SetView($gmap, $address)
; Parameters ....:  $gmap           - The Google Map object from the function "_GUICtrlGoogleMap_Create".
;                   $address        - An address (either a location or latitude and longitude) to center the map on
;                    ie. both "Sydney, New South Wales, Australia" and "-34.397, 150.644" are valid.
; Return values .:  On Success      - Returns True.
;       On Failure      - Returns False.
; Author ........:  seangriffin
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:  Yes
;
; ;==========================================================================================
Func _GUICtrlGoogleMap_SetView($this, $address)
    Local $latlng[2]

    $latlng = $this.GetLatLng($address)
    $this.gmap.document.parentwindow.execScript("move_map(" & $latlng[0] & "," & $latlng[1] & ");")
    Return True
EndFunc ;==>_GUICtrlGoogleMap_SetView

; #FUNCTION# ;===============================================================================
;
; Name...........:  _GUICtrlGoogleMap_ZoomView()
; Description ...:  Zooms the center of a Google Map to a new scale.
; Syntax.........:  _GUICtrlGoogleMap_ZoomView($gmap, $scale)
; Parameters ....:  $gmap           - The Google Map object from the function "_GUICtrlGoogleMap_Create".
;                   $scale          - The level/scale to zoom the view to.
; Return values .:  On Success      - Returns True.
;       On Failure      - Returns False.
; Author ........:  seangriffin
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:  Yes
;
; ;==========================================================================================
Func _GUICtrlGoogleMap_ZoomView($this, $scale)
    $this.gmap.document.parentwindow.execScript("zoom_map(" & $scale & ");")
    Return True
EndFunc ;==>_GUICtrlGoogleMap_ZoomView

; #FUNCTION# ;===============================================================================
;
; Name...........:  _GUICtrlGoogleMap_AddMarker()
; Description ...:  Adds a marker to a Google Map.
; Syntax.........:  _GUICtrlGoogleMap_AddMarker($gmap, $address)
; Parameters ....:  $gmap           - The Google Map object from the function "_GUICtrlGoogleMap_Create".
;                   $address        - An address (either a location or latitude and longitude) to add the marker to
;                    ie. both "Sydney, New South Wales, Australia" and "-34.397, 150.644" are valid.
;                   $icon_url       - (Optional) A URL to an image that will be used for the icon of the marker.
; Return values .:  On Success      - Returns True.
;       On Failure      - Returns False.
; Author ........:  seangriffin
; Modified.......:
; Remarks .......:  This function must be used before any other function in the UDF is used.
;                   There is currently a clipping problem with the control, where the video
;                   is overdrawn by any other window that overlaps it. There is no known
;                   solution at this time.
;
; Related .......:
; Link ..........:
; Example .......:  Yes
;
; ;==========================================================================================
Func _GUICtrlGoogleMap_AddMarker($this, $address, $icon_url = "")
    Local $latlng[2]

    $latlng = $this.GetLatLng($address)

    $this.gmap.document.parentwindow.execScript("addMarker(" & $latlng[0] & "," & $latlng[1] & ",'" & $icon_url & "');")

    Return True
EndFunc ;==>_GUICtrlGoogleMap_AddMarker

; #FUNCTION# ;===============================================================================
;
; Name...........:  _GUICtrlGoogleMap_HideAllMarkers()
; Description ...:  Hides all the markers on a Google Map (previously created by the function "_GUICtrlGoogleMap_AddMarker").
; Syntax.........:  _GUICtrlGoogleMap_HideAllMarkers($gmap)
; Parameters ....:  $gmap           - The Google Map object from the function "_GUICtrlGoogleMap_Create".
; Return values .:  On Success      - Returns True.
;       On Failure      - Returns False.
; Author ........:  seangriffin
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:  Yes
;
; ;==========================================================================================
Func _GUICtrlGoogleMap_HideAllMarkers($this)
    $this.gmap.document.parentwindow.execScript("clearMarkers();")
    Return True
EndFunc ;==>_GUICtrlGoogleMap_HideAllMarkers

; #FUNCTION# ;===============================================================================
;
; Name...........:  _GUICtrlGoogleMap_ShowAllMarkers()
; Description ...:  Shows all the markers on a Google Map (previously hidden by the function "_GUICtrlGoogleMap_HideAllMarkers").
; Syntax.........:  _GUICtrlGoogleMap_ShowAllMarkers($gmap)
; Parameters ....:  $gmap           - The Google Map object from the function "_GUICtrlGoogleMap_Create".
; Return values .:  On Success      - Returns True.
;       On Failure      - Returns False.
; Author ........:  seangriffin
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:  Yes
;
; ;==========================================================================================
Func _GUICtrlGoogleMap_ShowAllMarkers($this)
    $this.gmap.document.parentwindow.execScript("showMarkers();")
    Return True
EndFunc ;==>_GUICtrlGoogleMap_ShowAllMarkers

; #FUNCTION# ;===============================================================================
;
; Name...........:  _GUICtrlGoogleMap_DeleteAllMarkers()
; Description ...:  Deletes all the markers on a Google Map (previously created by the function "_GUICtrlGoogleMap_AddMarker").
; Syntax.........:  _GUICtrlGoogleMap_DeleteAllMarkers($gmap)
; Parameters ....:  $gmap           - The Google Map object from the function "_GUICtrlGoogleMap_Create".
; Return values .:  On Success      - Returns True.
;       On Failure      - Returns False.
; Author ........:  seangriffin
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:  Yes
;
; ;==========================================================================================
Func _GUICtrlGoogleMap_DeleteAllMarkers($this)
    $this.gmap.document.parentwindow.execScript("deleteMarkers();")
    Return True
EndFunc ;==>_GUICtrlGoogleMap_DeleteAllMarkers

; #FUNCTION# ;===============================================================================
;
; Name...........:  _GUICtrlGoogleMap_ViewAllMarkers()
; Description ...:  Sets the view of a Google Map to fit all the markers (previously created by the function "_GUICtrlGoogleMap_AddMarker")..
; Syntax.........:  _GUICtrlGoogleMap_ViewAllMarkers($gmap)
; Parameters ....:  $gmap           - The Google Map object from the function "_GUICtrlGoogleMap_Create".
; Return values .:  On Success      - Returns True.
;       On Failure      - Returns False.
; Author ........:  seangriffin
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:  Yes
;
; ;==========================================================================================
Func _GUICtrlGoogleMap_ViewAllMarkers($this)
    $this.gmap.document.parentwindow.execScript("viewMarkers();")
    Return True
EndFunc ;==>_GUICtrlGoogleMap_ViewAllMarkers

"Google Maps Example.au3"

#include <Google Maps.au3>

_AutoItObject_Startup()

Global $googlemap = GoogleMap()

; Setup Main GUI
Global $main_gui = GUICreate("Google Maps UDF Example", 800, 600, -1, -1, BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX))
Global $gmap_ctrl = $googlemap.Create(0, 10, 800, 450, "Palm Beach, Queensland, Australia", 12, True)
GUICtrlSetResizing($gmap_ctrl, $GUI_DOCKTOP)
Global $set_view_button = GUICtrlCreateButton("Set View to", 10, 495, 80, 20)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)
Global $set_view_input = GUICtrlCreateInput("Sydney, NSW", 100, 495, 180, 20)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)
Global $zoom_view_button = GUICtrlCreateButton("Zoom view to", 10, 515, 80, 20)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)
Global $zoom_view_input = GUICtrlCreateInput("6", 100, 515, 180, 20)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)
Global $add_marker_button = GUICtrlCreateButton("Add Marker to", 10, 535, 80, 20)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)
Global $add_marker_input = GUICtrlCreateInput("Currumbin, Queensland, Australia", 100, 535, 180, 20)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)
Global $view_markers_after_add_checkbox = GUICtrlCreateCheckbox("View All Markers after Add", 10, 555)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)
GUICtrlSetState($view_markers_after_add_checkbox, $GUI_CHECKED)
GUICtrlCreateLabel("Marker icon to use:", 300, 495, 100, 20)
Global $marker_icon_list = GUICtrlCreateList("", 300, 515, 100, 70)
GUICtrlSetData($marker_icon_list, "<default>|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z")
Global $hide_markers_button = GUICtrlCreateButton("Hide All Markers", 500, 495, 100, 20)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)
Global $show_markers_button = GUICtrlCreateButton("Show All Markers", 500, 515, 100, 20)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)
Global $delete_markers_button = GUICtrlCreateButton("Delete All Markers", 500, 535, 100, 20)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)
Global $view_markers_button = GUICtrlCreateButton("View All Markers", 500, 555, 100, 20)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)
Global $close_button = GUICtrlCreateButton("Close (Esc)", 650, 515, 80, 20)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)

Global $main_gui_accel[1][2] = [["{ESC}", $close_button]]

; Show Main GUI
GUISetState()

GUISetAccelerators($main_gui_accel)

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

; Main Loop
While 1
    Switch GUIGetMsg()
        Case $view_markers_button
            $googlemap.ViewAllMarkers()
        Case $delete_markers_button
            $googlemap.DeleteAllMarkers()
        Case $show_markers_button
            $googlemap.ShowAllMarkers()
        Case $hide_markers_button
            $googlemap.HideAllMarkers()
        Case $set_view_button
            $googlemap.SetView(GUICtrlRead($set_view_input))
        Case $zoom_view_button
            $googlemap.ZoomView(GUICtrlRead($zoom_view_input))
        Case $add_marker_button
            If StringCompare(GUICtrlRead($marker_icon_list), "<default>") <> 0 Then
                Global $marker_icon_url = "http://www.google.com/mapfiles/marker" & GUICtrlRead($marker_icon_list) & ".png"
            EndIf

            $googlemap.AddMarker(GUICtrlRead($add_marker_input), $marker_icon_url)

            If GUICtrlRead($view_markers_after_add_checkbox) = $GUI_CHECKED Then
                $googlemap.ViewAllMarkers()
            EndIf
        Case $GUI_EVENT_CLOSE, $close_button
            ExitLoop
    EndSwitch
WEnd

GUIDelete()

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local Static $EN_SETFOCUS = 0x100
    Local $nNotifyCode = BitShift($wParam, 16) ; high word
    Local $nID = BitAND($wParam, 0xFFFF) ; low word
    Local $hCtrl = $lParam

    Switch $nID
        Case $set_view_input
            Switch $nNotifyCode
                Case $EN_SETFOCUS
                    GUICtrlSetState($set_view_button, $GUI_DEFBUTTON)
            EndSwitch
        Case $zoom_view_input
            Switch $nNotifyCode
                Case $EN_SETFOCUS
                    GUICtrlSetState($zoom_view_button, $GUI_DEFBUTTON)
            EndSwitch
        Case $add_marker_input
            Switch $nNotifyCode
                Case $EN_SETFOCUS
                    GUICtrlSetState($add_marker_button, $GUI_DEFBUTTON)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>MY_WM_COMMAND
Edited by jaberwocky6669
Link to comment
Share on other sites

This is sweet! Thanks for sharing. :mellow:

Link to comment
Share on other sites

Great job. I really like it. There is a lot google APIs that can be taken advantage of just like this to make some really cool and useful programs. 5 stars from me.

You're absolutely right. I was kind of amazed that no-one had yet formalised a UDF for Google Maps. Well, haven't found one yet. Lots of topics with snippets of google map code however. I'm a bit reluctant to take on such a big UDF, but I figure if no-one's written it, and I need it, then I'll just go ahead and write it. The Google Maps API is certainly big, and I'm anticipating people might want all sorts of things put into the UDF. But it's a fun API, so I don't mind :mellow:

Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia
Link to comment
Share on other sites

Here is my AutoItObject version. You no longer have to declare $gmap in the example. Nor do you have to pass it into any of the functions! ...

How interesting. Thanks for sharing this.

I'm in two minds about OOP in general. I do like it when it's implemented well, with a well documented, well structured object hierarchy that the user can easily follow. Like many DOM and COM implementations. But I actually dislike tracing through OO code/script internally, to trace the flow of a script.

The AutoItObject UDF is very cool though, and I can see how good it would be in this UDF. If this UDF develops into something big, and a nicely structured object hierarchy can be made, then for sure, I'd move across to it. But not right now.

Wonder if other people have the same feelings about OOP? I've kind of got a love / hate relationship with it.

Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia
Link to comment
Share on other sites

This is awesome, great work!

Could this be used for Google Earth aswell ? it has an API also.

It would be very useful for me if there would be a GE version too. :mellow:

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

This is awesome, great work!

Could this be used for Google Earth aswell ? it has an API also.

It would be very useful for me if there would be a GE version too. :mellow:

Thanks.

Yeah as you say there is a Google Earth API which apparently allows Google Earth to be embedded in a webpage (and hence could be embedded in an AutoIT GUI as well). Was thinking how cool this would be too. It's not something I need right now, but I'd like to try. I was happy for this UDF to bits from the entire Google Maps API family (ie. google earth, static maps, etc.).

Will have a look sometime soon. Even if I just get a google earth map to display in AutoIT I think I'll be happy.

Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia
Link to comment
Share on other sites

That would be awesome.

Although I just signed up I've been lurking around for some time now, and already gotten help from you once or twice before, reading your threads about OCR :party: and I'm starting to get the hang of AU3, though mostly grabbing other peoples code, some here, some there, change some stuff and mix it toghether into something useful, it's always a start for learning until I get more skilled. :P

Sorry for the OT, I just wanted to clarify that it would be really appreciated if you would look into it, when/if you have the time. :mellow:

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

A more direct approach would be to use the COM api, skipping over the web page/html stuff.

http://earth.google.com/comapi/

For what its worth, there's no example code on that site yet. It shouldn't be too hard to figure out, though, as the classes and members are all documented.

Anyhow, back to the thread's main purpose - awesome! I've had a few ideas for apps using google maps but never really delved that far into it. It looked tedious and lengthy.

Way to go, seangriffin!

Link to comment
Share on other sites

A more direct approach would be to use the COM api, skipping over the web page/html stuff.

http://earth.google.com/comapi/

For what its worth, there's no example code on that site yet. It shouldn't be too hard to figure out, though, as the classes and members are all documented.

Anyhow, back to the thread's main purpose - awesome! I've had a few ideas for apps using google maps but never really delved that far into it. It looked tedious and lengthy.

Way to go, seangriffin!

Darn! I just went ahead tonight and implemented Google Earth into the UDF using Javascript :mellow: Yes, a COM implementation would be better, but as you say, not many examples. Have a look at my Javascript implementation in v0.2 of the UDF, because as far as performance goes it's superb.

Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia
Link to comment
Share on other sites

That would be awesome.

Although I just signed up I've been lurking around for some time now, and already gotten help from you once or twice before, reading your threads about OCR :party: and I'm starting to get the hang of AU3, though mostly grabbing other peoples code, some here, some there, change some stuff and mix it toghether into something useful, it's always a start for learning until I get more skilled. :party:

Sorry for the OT, I just wanted to clarify that it would be really appreciated if you would look into it, when/if you have the time. :P

I really apologise to yourself and anyone else who may have been asking me questions and I haven't responded to. I've had so many ideas for things to automate using AutoIT that I'm simply "flat out" just getting them into the forums and into UDFs, and have had little time to respond to or support users. But hearing all this great feedback really spurs me on! :mellow: Thank you all so much for your comments.

Stick with AutoIT Werty. I'm actually a software test automation professional by trade, and as an automation tool, AutoIT is really amazing. There's so much potential in this product, and what it already provides in many ways exceeds that of other commercial tools I've used.

Well I couldn't help myself, and I implemented the first Google Earth function today. Example provided above. See what you think :party:

Cheers,

Sean.

Edited by seangriffin

Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia
Link to comment
Share on other sites

Version 0.2 is now available for download.

Changes include:

  • Added the function "_GUICtrlGoogleEarth_Create".
A fast release of v0.2 to get Google Earth introduced. It looks great. Try the example provided in the top post.

By the way, if anyone's interested in the potential of Google Earth technology, check out this link:

http://code.google.com/apis/earth/documentation/examples.html

I was amazed at the Monster Milktruck and Driving Simulator examples!

Edited by seangriffin

Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia
Link to comment
Share on other sites

Is there a way (presumably another function calling more javascript) to make this map a route? Preferably including the step-by-step directions, but even just showing the route on the map. Either calling a function with two addresses/coordinates as parameters, or else perhaps by adding two markers and somehow designating to route between the two.

This UDF is VERY nice. Thank you!!

Link to comment
Share on other sites

You should add a function to change the view style, map, satellite, hybrid, terrain.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...