Android Question [SOLVED and now I understand why] Find Location on street crossing another street

yfleury

Active Member
Licensed User
Longtime User
I have to calculate direction on 100 address (very near from each) Google directions limit it to 25 address. I have to deal with.

So I need to know the position of each of the intersecting streets, Any hints?
 

yfleury

Active Member
Licensed User
Longtime User
On maps.google.com, we can find it with a search like that
street1 & street2

what google api to find that?
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
On maps.google.com, we can find it with a search like that
street1 & street2

what google api to find that?
I thing is geocoding api. But I don't know how to write url to obtain latitude and longitude
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Try this one - you can get lat/long of any address


GeoCode (VB.NET edition):
 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
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
Ok I find how to write the url and I can get latitude and longitude.
But my app have to check if two streets have an intersection

On web browser I load this link (put your api key)
B4X:
https://maps.googleapis.com/maps/api/geocode/json?address=rue%20b%C3%A9gin%20and%20rue%20%C3%89vans,%20Dolbeau-mistassini,%20Canada&key=AIzaSy222222222222222

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.
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
Ok I find somting weird

In my sub up there, I use j.Download2 and the result was completly différent when I use j.Download

With j.Download, I have same result with web browser link. So now, I can get types "intersection"



B4X:
    j.Download("https://maps.googleapis.com/maps/api/geocode/json?address=" & Place & "&key=" &  Main.API_KEY)
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
you mean something like this?
 

Attachments

  • fleury.png
    fleury.png
    18.1 KB · Views: 216
  • fleury.txt
    1.3 KB · Views: 228
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
This morning I found out why I had so much difficulty with this thread.
On the documentation page
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"
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
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.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
see:

 
Upvote 0
Top