iamtheky Posted October 19, 2010 Share Posted October 19, 2010 Nice Script and Example, I added this snippet directly after you determine whether $instruction is an array, to make the 'instructions' for the route appear without the <b> tags expandcollapse popupif IsArray($instruction) Then ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; For $k = 0 to ubound($instruction) - 1 $strinstruction = string($instruction[$k][0]) $first = stringsplit($strinstruction, "<b>" , 2) $slash = _arrayfindall ($first , '/') For $i = 0 to ubound($slash) - 1 If $i <> 0 Then $slash[$i] = ($slash[$i]) - $i Endif _ArrayDelete ($first , $slash[$i]) Next $blanks = _arrayfindall ($first , '') For $i = 0 to ubound($blanks) - 1 If $i <> 0 Then $blanks[$i] = ($blanks[$i]) - $i Endif _ArrayDelete ($first , $blanks[$i]) Next $StrInstruction = _ArrayToString ($first , '') ;~ msgbox (0, '' , $strInstruction) $instruction[$k][0] = $strInstruction Next ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; for $instr_num = 0 to (UBound($instruction) - 1) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
laosoi Posted October 21, 2010 Share Posted October 21, 2010 Thank you so much for your UDF! Can you add one more feature: Add marker every time I click on the map! I can't check LAT/LONG under mouse cursor using this UDF(to add marker), and IE too! Only Firefox work fine, but i hope you help me do this for your UDF. Best regards, Link to comment Share on other sites More sharing options...
fenerek Posted January 10, 2011 Share Posted January 10, 2011 How to add marker every time I click on the map? Thank you for this UDF Link to comment Share on other sites More sharing options...
JCarson Posted January 10, 2011 Share Posted January 10, 2011 I'd like to give this a go, just one question. Can you get route information (time, etc) for a route with multiple destinations? Thanks in advance, Carson Link to comment Share on other sites More sharing options...
spin0us Posted May 30, 2011 Share Posted May 30, 2011 (edited) I recently use this UDF for a project. All worked perfectly until today. A launched another time the demo script to make some snapshot and nothing work anymore ... I got this error: Google Maps.au3 (86) : ==> Array variable subscript badly formatted.: $latlng[0] = $geocode_line[_ArraySearch($geocode_line, """lat"":", 0, 0, 1, 1)] $latlng[0] = $geocode_line[^ ERROR What the hell is that ? PS: I've tried it on 3 others PC to check if it's not due to an OS update ... and nothing work too Edited May 30, 2011 by spin0us Link to comment Share on other sites More sharing options...
spin0us Posted May 30, 2011 Share Posted May 30, 2011 Ok so in fact i've found the source of the probleme. It's a space in the google response. I've change : $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) To : $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) There is a new space before the : This solve the error. Link to comment Share on other sites More sharing options...
t0nZ Posted July 11, 2011 Share Posted July 11, 2011 Ok so in fact i've found the source of the probleme. It's a space in the google response. I've change : $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) To : $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) There is a new space before the : This solve the error. Tested ! Solution works! I use this UDF daily in my own helpdesk software. Thanx. Link to comment Share on other sites More sharing options...
bb01 Posted July 12, 2011 Share Posted July 12, 2011 (edited) Started Getting an error today the script.. was working fine till today... Ok fixed it, turned out that it was calling an old ver of google maps.au3 in my include folder... 1 thing i'm looking to change is the distance from meters to miles & time from seconds to minutes. Edited July 21, 2011 by bb01 Link to comment Share on other sites More sharing options...
bb01 Posted July 21, 2011 Share Posted July 21, 2011 is there a way of being able to add a print button (eg print the map & directions)? Link to comment Share on other sites More sharing options...
kescho Posted September 11, 2011 Share Posted September 11, 2011 (edited) Hello. I was testing this UDF, but I never got the map centered at the location I typed in (it was always somewhere else - few km away of the typed location). So I made a little change to it and now the map is always centered at the wanted location. Then I changed a little the showing of markers. So for example at startup of the example, the map centers at some location and adds a marker there. When a new location is typed into the imputbox, then the old marker stayed at the startup location and new marker was not shown. Now when a new location is typed, then also a new marker is shown and the old marker is deleted. Also when a route is shown on the map, all old markers are deleted and only the needed markers are shown. The change of map centering: Original code (should be line 86 to 89): $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) Changed to...: For $latlng_search = 1 To $geocode_line[0] If StringInStr($geocode_line[$latlng_search], """location"" : {") Then $latlng[0] = $geocode_line[$latlng_search + 1] $latlng[0] = StringStripWS(StringReplace(StringReplace($latlng[0], """lat"" :", ""), ",", ""), 3) $latlng[1] = $geocode_line[$latlng_search + 2] $latlng[1] = StringStripWS(StringReplace(StringReplace($latlng[1], """lng"" :", ""), ",", ""), 3) EndIf Next Changes made to markers: func _GUICtrlGoogleMap_SetView($gmap, $address) Local $latlng[2] $latlng = _GUICtrlGoogleMap_GetLatLng($address) $gmap.document.parentWindow.execScript("deleteMarkers();"); <== added $gmap.document.parentWindow.execScript("move_map(" & $latlng[0] & "," & $latlng[1] & ");") $gmap.document.parentWindow.execScript("addMarker(" & $latlng[0] & "," & $latlng[1] & ");"); <== added Return True EndFunc ... and ... func _GUICtrlGoogleMap_AddRoute($gmap, $start_location, $end_location, $travel_mode = 0) $gmap.document.parentWindow.execScript("deleteMarkers();"); <== added $gmap.document.parentWindow.eval("calcRoute(""" & $start_location & """, """ & $end_location & """, " & $travel_mode & ", 0);") Return True EndFunc Somehow I can't figure out how to add an attachment... so here is the whole changed UDF in code... expandcollapse popup#include-once #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.4 Last Update: 10/06/10 Requirements: AutoIt3 3.2 or higher Changelog: ---------10/06/10---------- v0.4 Updated the function "_GUICtrlGoogleMap_Create" to add Javascript for calculating directions. Also had to split $html, because it's definition was too large causing a runtime error. Changed the Main GUI of the example to include tabs. Added a Directions tab in the example, with many Directions related controls. Added the functions "_GUICtrlGoogleMap_AddRoute" and "_GUICtrlGoogleMap_GetRoute". ---------08/06/10---------- v0.3 Improved performance in "_GUICtrlGoogleMap_Create" by moving 'document.body.scroll = "no"' to the html onload event, and removing _IELoadWait. Added 4 new parameters ($map_type, $navigation_style, $scale_style, $map_type_style) to "_GUICtrlGoogleMap_Create" for initializing map type and map controls. Added the function "_GUICtrlGoogleMap_SetMapType" for changing map type. Added a "Hide Map" checkbox to the example, to demonstrate the use of $gmap_ctrl. Changed the $hide_markers_button and $show_markers_button controls in the example to a checkbox. ---------08/06/10---------- v0.2 Added the function "_GUICtrlGoogleEarth_Create". ---------06/06/10---------- v0.1 Initial release. #ce #EndRegion Header #Region Global Variables and Constants #EndRegion Global Variables and Constants #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($address) Local $latlng[2], $latlng_search = 0 $address_part = StringSplit($address, ",") _ArrayDelete($address_part, 0) ; if the geocode is a lat long if UBound($address_part) = 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 $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET","http://maps.google.com/maps/api/geocode/json?address=" & $address & "&sensor=false") $oHTTP.Send() $HTMLSource = $oHTTP.Responsetext $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) For $latlng_search = 1 To $geocode_line[0] If StringInStr($geocode_line[$latlng_search], """location"" : {") Then $latlng[0] = $geocode_line[$latlng_search + 1] $latlng[0] = StringStripWS(StringReplace(StringReplace($latlng[0], """lat"" :", ""), ",", ""), 3) $latlng[1] = $geocode_line[$latlng_search + 2] $latlng[1] = StringStripWS(StringReplace(StringReplace($latlng[1], """lng"" :", ""), ",", ""), 3) EndIf Next EndIf Return $latlng EndFunc ; #FUNCTION# ;=============================================================================== ; ; Name...........: _GUICtrlGoogleMap_Create() ; Description ...: Creates a Google Map control. ; Syntax.........: _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) ; 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. ; $map_type - 0 = Sets the map type to roadmap ; 1 = Sets the map type to satellite ; 2 = Sets the map type to hybrid ; 3 = Sets the map type to terrain ; $navigation_style - 0 = Disable the Navigation control ; 1 = Enable the Navigation control with a small style ; 2 = Enable the Navigation control with a zoom pan style ; 3 = Enable the Navigation control with a android style ; 4 = Enable the Navigation control with a default style ; $scale_style - 0 = Disable the Scale control ; 1 = Enable the Scale control ; $map_type_style - 0 = Disable the MapType control ; 1 = Enable the MapType control with a horizontal bar style ; 2 = Enable the MapType control with a dropdown menu style ; 3 = Enable the MapType control with a default style ; 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(ByRef $gmap, $left, $top, $width, $height, $address, $zoom = 8, $marker = True, $map_type = 0, $navigation_style = 0, $scale_style = 0, $map_type_style = 0) local Const $map_type_html[4] = [ _ "mapTypeId: google.maps.MapTypeId.ROADMAP", _ "mapTypeId: google.maps.MapTypeId.SATELLITE", _ "mapTypeId: google.maps.MapTypeId.HYBRID", _ "mapTypeId: google.maps.MapTypeId.TERRAIN"] local Const $navigation_style_html[5] = [ _ "", _ "navigationControl: true, navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL}, ", _ "navigationControl: true, navigationControlOptions: {style: google.maps.NavigationControlStyle.ZOOM_PAN}, ", _ "navigationControl: true, navigationControlOptions: {style: google.maps.NavigationControlStyle.ANDROID}, ", _ "navigationControl: true, navigationControlOptions: {style: google.maps.NavigationControlStyle.DEFAULT}, "] local Const $scale_style_html[2] = [ _ "", _ "scaleControl: true, "] local Const $map_type_style_html[4] = [ _ "", _ "mapTypeControl: true, mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR}, ", _ "mapTypeControl: true, mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}, ", _ "mapTypeControl: true, mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DEFAULT}, "] Local $latlng[2] $latlng = _GUICtrlGoogleMap_GetLatLng($address) Local Const $html1 = _ "<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 directionDisplay;" & @CRLF & _ " var directionsService = new google.maps.DirectionsService();" & @CRLF & _ " var map;" & @CRLF & _ " var markersArray = [];" & @CRLF & _ " function initialize() {" & @CRLF & _ " document.body.scroll = ""no"";" & @CRLF & _ " directionsDisplay = new google.maps.DirectionsRenderer();" & @CRLF & _ " var latlng = new google.maps.LatLng(" & $latlng[0] & "," & $latlng[1] & ");" & @CRLF & _ " var myOptions = {" & @CRLF & _ " zoom: " & $zoom & "," & @CRLF & _ " center: latlng," & @CRLF & _ " disableDefaultUI: true," & @CRLF & _ $navigation_style_html[$navigation_style] & @CRLF & _ $scale_style_html[$scale_style] & @CRLF & _ $map_type_style_html[$map_type_style] & @CRLF & _ $map_type_html[$map_type] & @CRLF & _ " };" & @CRLF & _ " map = new google.maps.Map(document.getElementById(""map_canvas""), myOptions);" & @CRLF & _ " directionsDisplay.setMap(map);" & @CRLF & _ " if (" & StringLower($marker) & ") {" & @CRLF & _ " addMarker(" & $latlng[0] & "," & $latlng[1] & ");" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " function calcRoute(start, end, travel_mode_num, action) {" & @CRLF & _ " var travel_mode = [google.maps.DirectionsTravelMode.DRIVING, google.maps.DirectionsTravelMode.WALKING, google.maps.DirectionsTravelMode.BICYCLING];" & @CRLF & _ " var request = {" & @CRLF & _ " origin:start," & @CRLF & _ " destination:end," & @CRLF & _ " travelMode: travel_mode[travel_mode_num]" & @CRLF & _ " };" & @CRLF & _ " var myout = """";" & @CRLF & _ " directionsService.route(request, function(result, status) {" & @CRLF & _ " if (status == google.maps.DirectionsStatus.OK) {" & @CRLF & _ " if (action == 0) {" & @CRLF & _ " directionsDisplay.setDirections(result);" & @CRLF & _ " } else {" & @CRLF & _ " var myRoute = result.routes[0].legs[0];" & @CRLF & _ " myout = myRoute.distance.value + ""~"" + myRoute.duration.value + '\n';" & @CRLF & _ " for (var i = 0; i < myRoute.steps.length; i++) {" & @CRLF & _ " myout = myout + myRoute.steps[i].instructions + ""~"" + myRoute.steps[i].distance.value + ""~"" + myRoute.steps[i].duration.value + '\n'" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " });" & @CRLF & _ " return myout;" & @CRLF & _ " }" & @CRLF Local Const $html2 = _ " 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>" #cs " function addvat() {" & @CRLF & _ " var gert = [""5"",""4""];" & @CRLF & _ " var dude;" & @CRLF & _ " dude = gert[0];" & @CRLF & _ " return dude;" & @CRLF & _ " }" & @CRLF & _ #ce dim $html = $html1 & $html2 ;ConsoleWrite($html) ;Exit $gmap = _IECreateEmbedded () $gmap_ctrl = GUICtrlCreateObj($gmap, $left, $top, $width, $height) _IENavigate($gmap, "about:blank") _IEDocWriteHTML($gmap, $html) $gmap.refresh() Return $gmap_ctrl EndFunc ; #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($gmap, $address) Local $latlng[2] $latlng = _GUICtrlGoogleMap_GetLatLng($address) $gmap.document.parentWindow.execScript("deleteMarkers();") $gmap.document.parentWindow.execScript("move_map(" & $latlng[0] & "," & $latlng[1] & ");") $gmap.document.parentWindow.execScript("addMarker(" & $latlng[0] & "," & $latlng[1] & ");") Return True EndFunc ; #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($gmap, $scale) $gmap.document.parentWindow.execScript("zoom_map(" & $scale & ");") Return True EndFunc ; #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($gmap, $address, $icon_url = "") Local $latlng[2] $latlng = _GUICtrlGoogleMap_GetLatLng($address) $gmap.document.parentWindow.execScript("addMarker(" & $latlng[0] & "," & $latlng[1] & ",'" & $icon_url & "');") Return True EndFunc ; #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($gmap) $gmap.document.parentWindow.execScript("clearMarkers();") Return True EndFunc ; #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($gmap) $gmap.document.parentWindow.execScript("showMarkers();") Return True EndFunc ; #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($gmap) $gmap.document.parentWindow.execScript("deleteMarkers();") Return True EndFunc ; #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($gmap) $gmap.document.parentWindow.execScript("viewMarkers();") Return True EndFunc ; #FUNCTION# ;=============================================================================== ; ; Name...........: _GUICtrlGoogleMap_SetMapType() ; Description ...: Sets the type of map displayed. ; Syntax.........: _GUICtrlGoogleMap_SetMapType($gmap, $map_type) ; Parameters ....: $gmap - The Google Map object from the function "_GUICtrlGoogleMap_Create". ; $map_type - 0 = Sets the map type to roadmap ; 1 = Sets the map type to satellite ; 2 = Sets the map type to hybrid ; 3 = Sets the map type to terrain ; Return values .: On Success - Returns True. ; On Failure - Returns False. ; Author ........: seangriffin ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; ; ;========================================================================================== func _GUICtrlGoogleMap_SetMapType($gmap, $map_type) local Const $map_type_html[4] = [ _ "google.maps.MapTypeId.ROADMAP", _ "google.maps.MapTypeId.SATELLITE", _ "google.maps.MapTypeId.HYBRID", _ "google.maps.MapTypeId.TERRAIN"] $gmap.document.parentWindow.execScript("map.setMapTypeId(" & $map_type_html[$map_type] & ");") Return True EndFunc ; #FUNCTION# ;=============================================================================== ; ; Name...........: _GUICtrlGoogleMap_AddRoute() ; Description ...: Adds a route (visually) to the map. ; Syntax.........: _GUICtrlGoogleMap_AddRoute($gmap, $start_location, $end_location, $travel_mode = 0) ; Parameters ....: $gmap - The Google Map object from the function "_GUICtrlGoogleMap_Create". ; $start_location - The starting location of the route. ; Expressed as an address (ie. both "Sydney, New South Wales, Australia"). ; $end_location - The ending location of the route. ; Expressed as an address (ie. both "Sydney, New South Wales, Australia"). ; $travel_mode - 0 = Uses a travel mode of DRIVING ; 1 = Uses a travel mode of WALKING ; 2 = Uses a travel mode of BICYCLING ; Return values .: On Success - Returns True. ; On Failure - Returns False. ; Author ........: seangriffin ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; ; ;========================================================================================== func _GUICtrlGoogleMap_AddRoute($gmap, $start_location, $end_location, $travel_mode = 0) $gmap.document.parentWindow.execScript("deleteMarkers();") $gmap.document.parentWindow.eval("calcRoute(""" & $start_location & """, """ & $end_location & """, " & $travel_mode & ", 0);") Return True EndFunc ; #FUNCTION# ;=============================================================================== ; ; Name...........: _GUICtrlGoogleMap_GetRoute() ; Description ...: Gets directions for a route. ; Syntax.........: _GUICtrlGoogleMap_GetRoute($gmap, $start_location, $end_location, ByRef $distance, ByRef $duration, $travel_mode = 0) ; Parameters ....: $gmap - The Google Map object from the function "_GUICtrlGoogleMap_Create". ; $start_location - The starting location of the route. ; Expressed as an address (ie. both "Sydney, New South Wales, Australia"). ; $end_location - The ending location of the route. ; Expressed as an address (ie. both "Sydney, New South Wales, Australia"). ; $distance - The variable to hold the overall distance of the route. ; $duration - The variable to hold the overall duration of the route. ; $travel_mode - 0 = Uses a travel mode of DRIVING ; 1 = Uses a travel mode of WALKING ; 2 = Uses a travel mode of BICYCLING ; Return values .: On Success - Returns True. ; On Failure - Returns False. ; Author ........: seangriffin ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; ; ;========================================================================================== func _GUICtrlGoogleMap_GetRoute($gmap, $start_location, $end_location, ByRef $distance, ByRef $duration, $travel_mode = 0) Local $route_str, $step[1][3] $distance = "" $duration = "" ; Loop twice because sometimes it takes two calls to get route directions. I don't know why. for $i = 1 to 2 $route_str = $gmap.document.parentWindow.eval("calcRoute(""" & $start_location & """, """ & $end_location & """, " & $travel_mode & ", 1);") $route_str = StringStripWS($route_str, 2) $route_arr = StringSplit($route_str, @LF, 1) if $route_arr[0] > 1 Then ExitLoop Sleep(250) Next ; If no directions retrieved, then fail. if $route_arr[0] = 1 Then Return -1 _ArrayDelete($route_arr, 0) $leg = StringSplit($route_arr[0], "~", 1) $distance = $leg[1] $duration = $leg[2] _ArrayDelete($route_arr, 0) dim $step[UBound($route_arr)][3] for $i = 0 to (UBound($route_arr) - 1) $step_part = StringSplit($route_arr[$i], "~", 1) $step[$i][0] = $step_part[1] $step[$i][1] = $step_part[2] $step[$i][2] = $step_part[3] Next Return $step EndFunc ; #FUNCTION# ;=============================================================================== ; ; Name...........: _GUICtrlGoogleEarth_Create() ; Description ...: Creates a Google Map control. ; Syntax.........: _GUICtrlGoogleEarth_Create(ByRef $ge, $gmap_api_key, $left, $top, $width, $height, $address, $zoom = 10000, $fly_to_speed = "ge.SPEED_TELEPORT") ; Parameters ....: $ge - The embedded Google Earth object, required by the _GUICtrlGoogleEarth functions below. ; $gmap_api_key - A valid Google Maps API key (see Remarks 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 (in meters). ; $fly_to_speed - The speed to move to the above address. ; The range is 0.0 to 5.0. ; Using "ge.SPEED_TELEPORT" will move instantly. ; Return values .: On Success - Returns the identifier (controlID) of the new control. ; On Failure - Returns False. ; Author ........: seangriffin ; Modified.......: ; Remarks .......: The Google Earth Plug-in must be installed in your Internet Explorer browser ; prior to using this function. 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 function to work. ; You must obtain your own personal key from Google, and pass it into this ; function 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. ; Related .......: ; Link ..........: ; Example .......: Yes ; ; ;========================================================================================== func _GUICtrlGoogleEarth_Create(ByRef $ge, $gmap_api_key, $left, $top, $width, $height, $address, $zoom = 10000, $fly_to_speed = "ge.SPEED_TELEPORT") Local $latlng[2] $latlng = _GUICtrlGoogleMap_GetLatLng($address) Local Const $html = _ "<html>" & @CRLF & _ "<head>" & @CRLF & _ " <title>Sample</title>" & @CRLF & _ " <script src=""http://www.google.com/jsapi?key=" & $gmap_api_key & """> </script>" & @CRLF & _ " <script type=""text/javascript"">" & @CRLF & _ " var ge;" & @CRLF & _ " google.load(""earth"", ""1"");" & @CRLF & _ " function init() {" & @CRLF & _ " google.earth.createInstance('map3d', initCB, failureCB);" & @CRLF & _ " }" & @CRLF & _ " function initCB(instance) {" & @CRLF & _ " ge = instance;" & @CRLF & _ " ge.getWindow().setVisibility(true);" & @CRLF & _ " ge.getOptions().setFlyToSpeed(" & $fly_to_speed & ");" & @CRLF & _ " var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);" & @CRLF & _ " lookAt.setLatitude(" & $latlng[0] & ");" & @CRLF & _ " lookAt.setLongitude(" & $latlng[1] & ");" & @CRLF & _ " lookAt.setRange(" & $zoom & ");" & @CRLF & _ " ge.getView().setAbstractView(lookAt);" & @CRLF & _ " }" & @CRLF & _ " function failureCB(errorCode) {" & @CRLF & _ " }" & @CRLF & _ " google.setOnLoadCallback(init);" & @CRLF & _ " </script>" & @CRLF & _ "</head>" & @CRLF & _ "<body style=""margin:0px; padding:0px;"">" & @CRLF & _ " <div id=""map3d"" style=""width:100%; height:100%""></div>" & @CRLF & _ "</body>" & @CRLF & _ "</html>" $ge = _IECreateEmbedded () $ge_ctrl = GUICtrlCreateObj($ge, $left, $top, $width, $height) _IENavigate($ge, "about:blank") _IEDocWriteHTML($ge, $html) $ge.refresh() _IELoadWait($ge) $ge.document.body.scroll = "no" Return $ge_ctrl EndFunc I hope this changes will be useful to someone... If these changes could have been done an easier/simplier way, then please show me how... :-) I'm a beginner, I'm still learning, so please have patience with me...thanks Edited September 11, 2011 by kescho Link to comment Share on other sites More sharing options...
ReFran Posted September 12, 2011 Share Posted September 12, 2011 Hi, thanks for the update. Works fine for me. br, Reinhard Link to comment Share on other sites More sharing options...
Trash Posted February 13, 2012 Share Posted February 13, 2012 (edited) Hi, I had problems with the original UDF: If Google Maps couldn't find an address my program crashed. So I changed the function "_GUICtrlGoogleMap_GetLatLng($address)" a bit. Now it returns "Error 1", if Google could not find the address. This Part also contains the spaces mentioned before, so today this works perfectly: Func _GUICtrlGoogleMap_GetLatLng($address) Local $latlng[2] $address_part = StringSplit($address, ",") _ArrayDelete($address_part, 0) ; if the geocode is a lat long If UBound($address_part) = 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 $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "http://maps.google.com/maps/api/geocode/json?address=" & $address & "&sensor=false") $oHTTP.Send() $HTMLSource = $oHTTP.Responsetext $geocode_line = StringSplit($HTMLSource, @LF, 1) ; If Google could'nt find the address, we get the answer: ; "status" : "ZERO_RESULTS" If _ArraySearch($geocode_line, """status"" : ""ZERO_RESULTS""", 0, 0, 1, 1) = -1 Then ; _ArraySearch = "-1", if not found $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) Else ; "ZERO_RESULTS" SetError(1) EndIf EndIf Return $latlng EndFunc ;==>_GUICtrlGoogleMap_GetLatLng Hope, this will help somebody... Regards Edited February 13, 2012 by Trash Link to comment Share on other sites More sharing options...
jdc928 Posted June 29, 2012 Share Posted June 29, 2012 First Off, Let me just say that this UDF is amazing! One of the best I've seen for autoit. I am using it for live tracking, plotting and navigation for some underwater ROV's. Here's where I'm having an issue: I am able to use the maps api, retrieve data from the ROV's gps unit, and keep the map centered on the ROV's actual location, but I'm not seeing a way to do this with the earth portion of the plugin. Am I missing something or is it just not possible at the moment. Again, thanks for what you've already created, it's great! Link to comment Share on other sites More sharing options...
pumalife Posted July 8, 2012 Share Posted July 8, 2012 First Off, Let me just say that this UDF is amazing! One of the best I've seen for autoit. I am using it for live tracking, plotting and navigation for some underwater ROV's. Here's where I'm having an issue: I am able to use the maps api, retrieve data from the ROV's gps unit, and keep the map centered on the ROV's actual location, but I'm not seeing a way to do this with the earth portion of the plugin. Am I missing something or is it just not possible at the moment.Again, thanks for what you've already created, it's great!hey jdc928How do you add GPS ability to this map? this feature would be really useful to me. did you figure it out for google earth? Link to comment Share on other sites More sharing options...
Acanis Posted September 16, 2013 Share Posted September 16, 2013 D:\AutoIt3\Include\IE.au3 (3690) : ==> The requested action with this object has failed.: Local $oTemp = $o_object.document Local $oTemp = $o_object.document^ ERROR Any idea?! Link to comment Share on other sites More sharing options...
neonflux Posted October 3, 2013 Share Posted October 3, 2013 (edited) Hi all, I've a little question about this UDF... I'm trying to make a path with this tool by a list of coordinates form a .GPX file I've put some data in route function but the path wil show only the last two points and the others are cleared... Maybe this function is only for create a path between only 2 points only and not to create a path of waypoints? Any idea? Edit: Ok, done... I've edited the UDF and added two new function to work with polylines: _GUICtrlGoogleMap_AddPolyline($gmap, $lat, $lng) <-- this is for to add a single checkpoint to the line (note that i'm working with latitude and longitude only and not with address cause using the address translate for 2600 coordinate point was slowing down alot) _GUICtrlGoogleMap_ShowPolyline($gmap) <-- To show the polyline after that all steps went added This works for me (at least for my need) Edited October 20, 2013 by neonflux Link to comment Share on other sites More sharing options...
michaelslamet Posted November 17, 2013 Share Posted November 17, 2013 I had a problem with_GUICtrlGoogleMap_GetRoute Using the example (Google Maps Example.au3) found at the #1 post, the $distance and $duration always return nothing, no matter what is the $start_location and $end_location. Maybe there is a change on the Google API? Please enlight me and thank you Link to comment Share on other sites More sharing options...
michaelslamet Posted November 19, 2013 Share Posted November 19, 2013 I had a problem with_GUICtrlGoogleMap_GetRoute Using the example (Google Maps Example.au3) found at the #1 post, the $distance and $duration always return nothing, no matter what is the $start_location and $end_location. Maybe there is a change on the Google API? Please enlight me and thank you Is this UDF still maintained? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 19, 2013 Moderators Share Posted November 19, 2013 michaelslamet,seangriffin is an irregular visitor to the forum, so you will just have to be patient. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
michaelslamet Posted November 19, 2013 Share Posted November 19, 2013 michaelslamet, seangriffin is an irregular visitor to the forum, so you will just have to be patient. M23 Hi Melba Ok, I am waiting patiently while trying to find the solution Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now