Private Function GetAddressGeoCode(Address As String) As String
Dim wc As New System.Net.WebClient
Try
Dim url As String = ""
Dim str As String = ""
url = "https://geocoder.api.here.com/6.2/geocode.xml?app_id=YOR_API_ID&app_code=YOUR_API_CODE&searchtext=" & Address
With wc
str = .DownloadString(url)
End With
str = ReadXML(str)
Return str
Catch ex As Exception
Functions.SaveError(ex, "GetAddressGeoCode=" & GetClientID())
Return "Error"
Finally
wc = Nothing
End Try
End Function
I need the value of "types" like "types" : [ "intersection" ] but I don't know how.
B4X:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Rue Bégin & Rue Evans",
"short_name" : "Rue Bégin & Rue Evans",
"types" : [ "intersection" ] <<<<<<<<<<< I need this
},
{
"long_name" : "Dolbeau-Mistassini",
"short_name" : "Dolbeau-Mistassini",
"types" : [ "locality", "political" ]
},
I use this sub to obtain latitude and longitude.
B4X:
Sub TrouveUneIntersection(Place As String) As ResumableSub
Log ( Place)
Dim res() As Double = Array As Double(9999, 9999)
Dim j As HttpJob
j.Initialize("", Me)
j.Download2("https://maps.googleapis.com/maps/api/geocode/json", Array As String("key", Main.API_KEY, "address", Place))
Log ("https://maps.googleapis.com/maps/api/geocode/json?key=" & Main.API_KEY & "&address=" & Place)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim jp As JSONParser
jp.Initialize(j.GetString)
Dim m As Map = jp.NextObject
If m.Get("status") = "OK" Then
Dim results As List = m.Get("results")
If results.Size > 0 Then
Dim first As Map = results.Get(0)
Dim geometry As Map = first.Get("geometry")
Dim location As Map = geometry.Get("location")
res(0) = location.Get("lat")
res(1) = location.Get("lng")
End If
End If
Else
Log("Error!")
End If
j.Release
Return res
End Sub
If 2 streets have an intersection the json response have "types" : [ "intersection" ] not on parallel streets. So I have to check if it's an intersection or not.
Maybe a hint will be usefull.
Geocoding converts addresses into geographic coordinates to be placed on a map. Reverse Geocoding finds an address based on geographic coordinates or Place IDs.
developers.google.com
They say
Format plus codes as shown here (plus signs are url-escaped to %2B and spaces are url-escaped to %20)
So I have spaces are url-escaped to (%20) my address as follows Dim Place As String = "rue%20bégin%20and%20rue%20évans,%20Dolbeau-Mistassini"
j.Download and j.Download2 don't need to do it. I just need a plain address as follows
Dim Place As String = "rue bégin and rue évans, Dolbeau-Mistassini"
download2 url-escapes the (plain-text) parameters. download doesn't, so you need to take care of it. there are routines available to save you the trouble of parsing the url yourself by hand.
' UrlEncodeMap(input As Map) As String ' Converts a Map's keys/values to a URL encoded parameter string ' Following library is used ' B4J - jStringUtils ' B4A - StringUtils ' B4i - iStringUtils Sub UrlEncodeMap(input As Map) As String Dim sb As StringBuilder Dim su As StringUtils...