Categories
Uncategorized

How to Get Google Maps GPS Coordinates in AutoHotkey

This code returns the GPS coordinates of any point the mouse icon is hovered above in Google Maps using AutoHotkey.


; Right click the desired location in Google Maps. 
; It brings up a menu.
click, right 
sleep 400

; Highlight "What's Here?" by clicking the right arrow three times
Send {Right 3} 
Send {Enter} ; Selects "What's Here?"

Send ^+j ; Open Chrome Inspector console
sleep 1800

; Get the GPS coordinates, which are in the format of 35.878320, -97.394132
SendRaw copy(document.getElementsByClassName("widget-reveal-card-lat-lng")[0].innerHTML);
Sleep, 5
Send {Enter}

; Copy the value to the clipboard
ClipWait, 5

; Check for errors
if ErrorLevel
{
    MsgBox, The attempt to copy coordinates onto the clipboard failed.
    return
}

; Move the coordinates value from the clipboard to a variable
fullCoordinates := clipboard
Sleep, 20

; Empty the clipboard.
clipboard =   
Sleep, 200

Send ^+j ; Close Chrome Inspector console
sleep 50

; Split and set the full coordinates into longitude and lattitude
splittedCoordinates := strSplit(fullCoordinates,",") 

; The separate lattitude and longitude values
lattitude := Trim(splittedCoordinates[1]) ; looks like 35.878320
longitude := Trim(splittedCoordinates[2]) ; looks like -97.394132