Android Question Get the detailed address from Google Map Extra

BerlinCoder

Member
Licensed User
Hi,
I need to get the a proper address of a point on the map, but I do not want to get a Json string. I only need to have the street name, alley and the house number( optional ).

Best,
 

DonManfred

Expert
Licensed User
Longtime User
Use Google Geocode api, get the json-ressult. Parse the result and read the values from it.
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
Example, not running alone

B4X:
Sub GPS_LocationChanged (Location1 As Location)    
    GeoLat = Location1.Latitude
    GeoLong = Location1.Longitude
     'Log (GeoLat & " , " & GeoLong)
    
'Autodatenübernahme-----------------------------------------------------------
    Dim Latitude, Longitude As Double
    Latitude = GeoLat
    Longitude = GeoLong
    Geocoder1.GetFromLocation(Latitude, Longitude, 1, Null)
'Autodatenübernahme-----------------------------------------------------------

End Sub

Sub Geocoder1_GeocodeDone(Results() As Address, Tag As Object)
If Results.Length > 0 Then
    ImageView3.Visible = False
    ProgressBar2.Visible = False
    lblHausnummer.Visible = True
Dim Address1 As Address
  Dim i As Int
 
    For i = 0 To Results.Length-1
    Address1=Results(i)
    Geostrasse = (Address1.AddressLines.Get(0))
    Dim geostpr(2) As String 
    geostpr = Regex.Split(" ", (Address1.AddressLines.Get(1))) 
    Geoplz = geostpr(0)
    Geoort = geostpr(1)
    Next
Log(Geoplz & " " & Geoort & " - " & Geostrasse)
    lblHausnummer.Text = Geoplz & " " & Geoort & CRLF & Geostrasse
   
  Else
End If
End Sub

Sub ImageView3_Click

GPS1.Initialize("GPS") 'GPS starten

If GPS1.GPSEnabled = False Then
tt.showErrorToast("Bitte schalten Sie ihr GPS ein, sonst ist keine Automatische Suche des Standortes möglich! ")
Else
     ProgressBar2.Visible = True
    GPS1.Start(0, 0) 'Listen to GPS with no filters.
    Geocoder1.Initialize3("Geocoder1", "de", "DE")
End If
Geoplz = ""
Geoort = ""
Geostrasse = ""
End Sub
 
Upvote 0

BerlinCoder

Member
Licensed User
Example, not running alone

B4X:
Sub GPS_LocationChanged (Location1 As Location)  
    GeoLat = Location1.Latitude
    GeoLong = Location1.Longitude
     'Log (GeoLat & " , " & GeoLong)
  
'Autodatenübernahme-----------------------------------------------------------
    Dim Latitude, Longitude As Double
    Latitude = GeoLat
    Longitude = GeoLong
    Geocoder1.GetFromLocation(Latitude, Longitude, 1, Null)
'Autodatenübernahme-----------------------------------------------------------

End Sub

Sub Geocoder1_GeocodeDone(Results() As Address, Tag As Object)
If Results.Length > 0 Then
    ImageView3.Visible = False
    ProgressBar2.Visible = False
    lblHausnummer.Visible = True
Dim Address1 As Address
  Dim i As Int

    For i = 0 To Results.Length-1
    Address1=Results(i)
    Geostrasse = (Address1.AddressLines.Get(0))
    Dim geostpr(2) As String
    geostpr = Regex.Split(" ", (Address1.AddressLines.Get(1)))
    Geoplz = geostpr(0)
    Geoort = geostpr(1)
    Next
Log(Geoplz & " " & Geoort & " - " & Geostrasse)
    lblHausnummer.Text = Geoplz & " " & Geoort & CRLF & Geostrasse
 
  Else
End If
End Sub

Sub ImageView3_Click

GPS1.Initialize("GPS") 'GPS starten

If GPS1.GPSEnabled = False Then
tt.showErrorToast("Bitte schalten Sie ihr GPS ein, sonst ist keine Automatische Suche des Standortes möglich! ")
Else
     ProgressBar2.Visible = True
    GPS1.Start(0, 0) 'Listen to GPS with no filters.
    Geocoder1.Initialize3("Geocoder1", "de", "DE")
End If
Geoplz = ""
Geoort = ""
Geostrasse = ""
End Sub

Vielen danke! But I need a sample with google map extra ...!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I need a sample with google map extra ...!
It is NOT possible just with google maps and google maps extras.... !!!!

You need to use a third party api (in this case a google api) to do so... See @Wolli013 answer and search the forum for geocoding
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
please put here an example?
B4X:
    Dim j As HttpJob
    j.Initialize("",Me)
    j.Download("https://maps.google.com/maps/api/geocode/json?latlng=50.7907,6.4659&sensor=False")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        'The result is a json string. We parse it and log the fields.
        Dim jp As JSONParser
        jp.Initialize(j.GetString)
        Dim root As Map = jp.NextObject
        Dim results As List = root.Get("results")
        For Each colresults As Map In results
            Dim formatted_address As String = colresults.Get("formatted_address")
            Dim types As List = colresults.Get("types")
            For Each coltypes As String In types
            Next
            Dim geometry As Map = colresults.Get("geometry")
            Dim viewport As Map = geometry.Get("viewport")
            Dim southwest As Map = viewport.Get("southwest")
            Dim lng As Double = southwest.Get("lng")
            Dim lat As Double = southwest.Get("lat")
            Dim northeast As Map = viewport.Get("northeast")
            Dim lng As Double = northeast.Get("lng")
            Dim lat As Double = northeast.Get("lat")
            Dim location As Map = geometry.Get("location")
            Dim lng As Double = location.Get("lng")
            Dim lat As Double = location.Get("lat")
            Dim location_type As String = geometry.Get("location_type")
            Dim address_components As List = colresults.Get("address_components")
            For Each coladdress_components As Map In address_components
                Dim types As List = coladdress_components.Get("types")
                For Each coltypes As String In types
                Next
                Dim short_name As String = coladdress_components.Get("short_name")
                Dim long_name As String = coladdress_components.Get("long_name")
            Next
            Dim place_id As String = colresults.Get("place_id")
        Next
        Dim status As String = root.Get("status")
    End If
    j.Release
 
Upvote 0
Top