Jump to content
Sign in to follow this  
golfinhu

convert address to lat lng (google maps)

Recommended Posts

golfinhu

Hi, i'm trying to convert on address of the google maps in lat and lng, but i'm getting error with winhttp:

anyone can help me, please?

 

My code:

 

#include <Array.au3>


;It Don't Work
Local $sAdress = "Palm Beach QLD, Australia", $latlng[2]
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET", "https://www.google.com.br/maps/place/" & StringReplace($sAdress, " ", "+") & "/")
$oHTTP.Send()

$coords = StringRegExp($oHTTP.Responsetext, "(-?\d{2,4}\.\d+)", 3)
$oHTTP.close()
$latlng[0] = $coords[2]
$latlng[1] = $coords[1]
_ArrayDisplay($latlng)


;It work, but i can't change the address:
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET", "https://www.google.com.br/search?tbm=map&fp=1&authuser=0&hl=pt-BR&pb=!4m12!1m3!1d23606.581874621756!2d153.46281855!3d-28.1162266!2m3!1f0!2f0!3f0!3m2!1i1366!2i644!4f13.1!7i10!10b1!12m3!2m1!20e3!16b1!19m9!1e1!1e2!1e5!1e3!1e10!1e12!1e15!1e27!4smaps_sv.tactile!20m18!1e1!1e2!1e5!1e11!1e4!1e3!1e10!1e12!1e15!1e27!1e24!2m2!1i203!2i100!3m1!2i100!5smaps_sv.tactile!9b0!22m5!1sMT1GVZisK4LIsQTJnIAg!4m1!2i11887!7e81!12e3!26m6!1e12!1e15!1e13!1e3!1e27!4smaps_sv.tactile!30m28!1m6!1m2!1i0!2i0!2m2!1i480!2i644!1m6!1m2!1i1316!2i0!2m2!1i1366!2i644!1m6!1m2!1i0!2i0!2m2!1i1366!2i20!1m6!1m2!1i0!2i624!2m2!1i1366!2i644!37m1!1e81&q=Palm%20Beach%20QLD%2C%20Australia&oq=Palm%20Beach%20QLD%2C%20Australia&gs_l=maps.12...0.0.1.14195.0.0.0.0.0.0.0.0..0.0.msedr...0...1ac..61.maps..0.0.0.&tch=1&ech=1&psi=MT1GVZisK4LIsQTJnIAg.1430666546686.1")
$oHTTP.Send()

$coords = StringRegExp($oHTTP.Responsetext, "(-?\d{2,4}\.\d+)", 3)
$oHTTP.close()
$latlng[0] = $coords[2]
$latlng[1] = $coords[1]
_ArrayDisplay($latlng)


;The HTTP HEADER code:

;~ https://www.google.com.br/search?tbm=map&fp=1&authuser=0&hl=pt-BR&pb=!4m12!1m3!1d23606.581874621756!2d153.46281855!3d-28.1162266!2m3!1f0!2f0!3f0!3m2!1i1366!2i644!4f13.1!7i10!10b1!12m3!2m1!20e3!16b1!19m9!1e1!1e2!1e5!1e3!1e10!1e12!1e15!1e27!4smaps_sv.tactile!20m18!1e1!1e2!1e5!1e11!1e4!1e3!1e10!1e12!1e15!1e27!1e24!2m2!1i203!2i100!3m1!2i100!5smaps_sv.tactile!9b0!22m5!1sMT1GVZisK4LIsQTJnIAg!4m1!2i11887!7e81!12e3!26m6!1e12!1e15!1e13!1e3!1e27!4smaps_sv.tactile!30m28!1m6!1m2!1i0!2i0!2m2!1i480!2i644!1m6!1m2!1i1316!2i0!2m2!1i1366!2i644!1m6!1m2!1i0!2i0!2m2!1i1366!2i20!1m6!1m2!1i0!2i624!2m2!1i1366!2i644!37m1!1e81&q=Palm%20Beach%20QLD%2C%20Australia&oq=Palm%20Beach%20QLD%2C%20Australia&gs_l=maps.12...0.0.1.14195.0.0.0.0.0.0.0.0..0.0.msedr...0...1ac..61.maps..0.0.0.&tch=1&ech=1&psi=MT1GVZisK4LIsQTJnIAg.1430666546686.1

;~ GET /search?tbm=map&fp=1&authuser=0&hl=pt-BR&pb=!4m12!1m3!1d23606.581874621756!2d153.46281855!3d-28.1162266!2m3!1f0!2f0!3f0!3m2!1i1366!2i644!4f13.1!7i10!10b1!12m3!2m1!20e3!16b1!19m9!1e1!1e2!1e5!1e3!1e10!1e12!1e15!1e27!4smaps_sv.tactile!20m18!1e1!1e2!1e5!1e11!1e4!1e3!1e10!1e12!1e15!1e27!1e24!2m2!1i203!2i100!3m1!2i100!5smaps_sv.tactile!9b0!22m5!1sMT1GVZisK4LIsQTJnIAg!4m1!2i11887!7e81!12e3!26m6!1e12!1e15!1e13!1e3!1e27!4smaps_sv.tactile!30m28!1m6!1m2!1i0!2i0!2m2!1i480!2i644!1m6!1m2!1i1316!2i0!2m2!1i1366!2i644!1m6!1m2!1i0!2i0!2m2!1i1366!2i20!1m6!1m2!1i0!2i624!2m2!1i1366!2i644!37m1!1e81&q=Palm%20Beach%20QLD%2C%20Australia&oq=Palm%20Beach%20QLD%2C%20Australia&gs_l=maps.12...0.0.1.14195.0.0.0.0.0.0.0.0..0.0.msedr...0...1ac..61.maps..0.0.0.&tch=1&ech=1&psi=MT1GVZisK4LIsQTJnIAg.1430666546686.1 HTTP/1.1
;~ Host: www.google.com.br
;~ User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0
;~ Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
;~ Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
;~ Accept-Encoding: gzip, deflate
;~ Referer: https://www.google.com.br/maps/place/Palm+Beach+QLD,+Australia/@-28.1162266,153.4628186,14z/data=!3m1!4b1!4m2!3m1!1s0x6b91036efd83396d:0x502a35af3dea560
;~ Cookie: PREF=ID=86aeb3b3ab77efdc:U=d54bb2b26ead2695:FF=0:TM=1430661647:LM=1430661830:S=koQiR27kXIHRQNyP; NID=67=nVH6ptiUT9O756Udaoxt5y-q_6WqQFynBmxgYx1OZ3yWv-BIvx29d0OxmknkS3ujqYWmEX0ZEcdEhTPjD94hs80gDg5kIAC3WvfY7pVWw3IU2EXlvCDZakMUiApLIuQS
;~ Connection: keep-alive

Thanks a lot

Share this post


Link to post
Share on other sites
darkshark

why u don't use IE lib?

Share this post


Link to post
Share on other sites
golfinhu

I want to do this with winttp, anyone know what's wrong? 

Thanks

Share this post


Link to post
Share on other sites
AspirinJunkie

Google offers a special API for this - why shouldn't use it?

An example:

Global $s_Address = "Palm Beach, QLD, Australia"

Global $s_Response = BinaryToString(InetRead("http://maps.googleapis.com/maps/api/geocode/json?address=" & _URIEncode($s_Address), 1))
Global $a_Result = StringRegExp($s_Response, '(?s)"location" .+?"lat"\s*:\s*(-?\d+\.\d+).+? "lng"\s*:\s*(-?\d+\.\d+)', 3)

ConsoleWrite(StringFormat("Address: %s\nLat: % 12.7f°\nLng: % 12.7f°\n", $s_Address, $a_Result[0], $a_Result[1]))


;~ Copyright: Prog@ndy
Func _URIEncode($sData)
    ; Prog@ndy
    Local $aData = StringSplit(BinaryToString(StringToBinary($sData,4),1),"")
    Local $nChar
    $sData=""
    For $i = 1 To $aData[0]
        ; ConsoleWrite($aData[$i] & @CRLF)
        $nChar = Asc($aData[$i])
        Switch $nChar
            Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126
                $sData &= $aData[$i]
            Case 32
                $sData &= "+"
            Case Else
                $sData &= "%" & Hex($nChar,2)
        EndSwitch
    Next
    Return $sData
EndFunc

 

Share this post


Link to post
Share on other sites
guinness

Google Maps API. I have used it in Android only, but it's there as an interface for using Google's Maps.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
AspirinJunkie

What api? 

​The one i used in the example that i gave you.

Share this post


Link to post
Share on other sites
golfinhu

Oh! Now I saw that you had put an example, I am very grateful for the help, I'll take a look at this api and try to use it, thank you for the help!

Share this post


Link to post
Share on other sites
Shane0000

 

#include <INet.au3>
$sDestination = "30.01231354,-87.15464"
$sLink_C = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='
$sData = _INetGetSource($sLink_C & $sDestination, TRUE)


$sDestination = "106+Deleware+Lane,New+York,New+York,10013"
$slink_D = "https://maps.googleapis.com/maps/api/geocode/json?address="
$sData = _INetGetSource($sLink_D & $sDestination, TRUE)

 

https://maps.googleapis.com/maps/api/geocode/json?address=106+Delaware+Lane,New+York,New+York,10013

Look at the API, an XML return is possible also. Also on this forum some where is an UDF to turn the resulting JSON into an object so that you can access the results such as: 

$oResult.results.item($i).address_components.item($ii).long_name
$oResult.results.item($i).geometry.location.lng

 

Also on the forum somewhere is a GoogleMaps UDF that has a gui example. (_Google Maps v2.au3 Google Maps Tool)

Edited by Shane0000
Added #include

Share this post


Link to post
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
Sign in to follow this  

×