Android Question [SOLVED] Geocoder Does Not Return any Addresses

mmieher

Active Member
Licensed User
Longtime User
The Geocoder library looks like exactly what I need, but this simple code below always logs "Address1.AddressLines.Size = 0". I am passing a valid latitude and longitude.

What am doing wrong?

B4X:
Sub Process_Globals
     Private GeoCoder1 As Geocoder
End Sub

Public Sub GetGPSAddress(inLat As Double, inLon As Double) As ResumableSub
   
    GeoCoder1.Initialize("Geocoder1")
    GeoCoder1.GetFromLocation(inLat,inLon,1,Null)
   
    Return 0
   
End Sub

Sub Geocoder1_GeocodeDone(Results() As Address, Tag As Object)
    If Results.Length>0 Then
        Dim Address1 As Address
        Dim i As Int
        For i=0 To Results.Length-1
            Address1=Results(i)
           
            LogColor("Address1.AddressLines.Size = " & Address1.AddressLines.Size, Colors.Red)
           
            If Address1.AddressLines.Size>0 Then
                Log(Address1.AddressLines.Get(0))
            End If
        Next
    Else
        Msgbox("GetFromLocation", "No Address matched the Latitude and Longitude")
    End If
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
Thanks, Don. I actually started with the Rest-Api. I keep getting a status of REQUEST_DENIED. I did go through the API key process on the Google Console. I did enable the Places API.
 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
In case this helps someone else, here is my reverse geocode solution:

B4X:
Sub RestAPI(inLat As Double, inLon As Double)
   
    Dim j As HttpJob
    j.Initialize("GetAddress",Me)
    j.Download2("https://maps.googleapis.com/maps/api/geocode/json", Array As String("latlng", inLat & "," & inLon,"key",API_KEY))
   
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim jp As JSONParser
        jp.Initialize(j.GetString)
        Dim root As Map = jp.NextObject
       
        If root.Get("status") = "OK" Then
            If root.Size > 0 Then
               
                Dim xmenu As List = root.Get("results")
                Dim addrComp As Map = xmenu.Get(0)
                Dim addrList As List = addrComp.Get("address_components")
               
                For i = 0 To addrList.Size-1
                       
                    Dim addrMap As Map = addrList.Get(i)
                    Dim tList As List = addrMap.Get("types")
                    Dim kType As String = tList.Get(0)
                   
                    Select Case kType
                        Case "locality"
                            Log("City = " & addrMap.Get("long_name"))
                           
                        Case "administrative_area_level_1"
                            Log("State = " & addrMap.Get("long_name"))
                           
                        Case "postal_code"
                            Log("Zip = " & addrMap.Get("short_name"))
                           
                        Case "country"
                            Log("Country = " & addrMap.Get("long_name"))
                       
                    End Select
                   
                Next
               
            End If
           
        End If
    Else
        Log("Error!")
    End If
    j.Release
   
End Sub
 
Upvote 0

wes58

Active Member
Licensed User
Longtime User
See Post #2!
Can you please follow forum rules/guidelines https://www.b4x.com/android/forum/threads/forum-guidelines.55632/
Guideline #1 Use common sense. (when posting).

I made a mistake and created a post with the same link as you, but there was no need, in my opinion, for you to reply to it. It doesn't help the OP, or anyone else. Common sense would tell you that!

If you really have to create a certain number of posts each day, why don't you help people that asked for your help in one of your libraries thread https://www.b4x.com/android/forum/t...m-and-floating-action-button-fab.65064/page-3.
People have been waiting for a couple of months now?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
was no need, in my opinion, for you to reply to it
In my opinion it was! And after your answer now it is! Check the thread before posting unrelated/already solved issues answers.

If you really have to create a certain number of posts each day, why don't you help people that asked for your help in one of your libraries thread https://www.b4x.com/android/forum/t...m-and-floating-action-button-fab.65064/page-3.
People have been waiting for a couple of months now?

It is NOT your job to say to me what i have to do and what not. Welcome on my ignorelist!
But thank you for pointing it out. I simply missed it; my answer will be of no help anyway.

And yes, i now regret writing a ContentProvider to help you....
 
Last edited:
Upvote 0

wes58

Active Member
Licensed User
Longtime User
In my opinion it was! And after your answer now it is! Check the thread before posting unrelated/already solved issues answers.
Why? Is it in another one of your unwritten forum Rules?
You never make mistakes, do you? I am sure that I could find similar situations where you posted the same solution after someone else did.
You just don't want to accept that you are wrong.
That's why there is a forum Guideline - #1 Use common sense.

COMMON SENSE is sound practical judgment concerning everyday matters, or a basic ability to perceive, understand, and judge that is shared by ("common to") nearly all people https://en.wikipedia.org/wiki/Common_sense
Think, how your post helped anyone? Why nobody else would post such a reply? Because it is a common sense.

And yes, i regret writing a ContentProvider now....
At least you could tell others that you stopped supporting the library.

It is NOT your job to say to me what i have to do and what not. Welcome on my ignorelist!
That really got under your skin, didn't it.

You see, I hope that you understand what you wrote. Read it again - "It is NOT your job to say to me what i have to do and what not".

That's exactly right. It applies to you as well - It is NOT your job to say to me (and other Forum users) what I (and other Forum users) have to do and what not.
If someone wants to ask another question in his/hers own thread - it is not your job to tell them that they can't do that.
If someone post the same solution after you did - it is not you job to judge them.
The Forum is for helping people not telling them what to do, just because you think that you know better, or because you decide on creating your own rules etc.
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
May I make an observation:

- We are are a very diverse community spread worldwide of many languages & cultures.

- Many here do not have English as their first language. Some cultures are very direct, other cultures perceive that directness as being rude.

- Trying to be smart or funny in somebody else's language is highly likely to fail and so give offence.

- Saying'I told you so' or ignoring someone is not well received in any culture.

We have a marvellous resource here. We are intelligent individuals who are all learning. We are able to communicate much better than this.
 
Upvote 0
Top