Android Code Snippet Google Maps POI details

In Google maps there are more than 100 million businesses and points of interest that are updated frequently through owner-verified listings and user-moderated contributions.
In order to get details of one of these, when an user click on it on maps, you need a key.

After followed this tutorial, add this code

B4X:
Wait For MapFragment1_Ready
    gmap  = MapFragment1.GetMap
    Dim jo As JavaObject
    jo = gmap
    Dim e As Object = jo.CreateEvent("com.google.android.gms.maps.GoogleMap.OnPoiClickListener", "poiClick", False)
    jo.RunMethod("setOnPoiClickListener", Array As Object(e))

Sub poiClick_Event (MethodName As String, Args() As Object) As ResumableSub
    Dim POI As JavaObject = Args(0)
'    Log(POI.GetField("name"))
'    Log(POI.GetFieldJO("latLng").GetField("latitude"))
'    Log(POI.GetFieldJO("latLng").GetField("longitude"))

    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download2("https://maps.googleapis.com/maps/api/place/details/json", _
        Array As String("key", API_KEY, "placeid", POI.GetField("placeId")))
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim jp As JSONParser
        jp.Initialize(j.GetString)
                'Get your details
    End If
    j.Release
    Return True
End Sub
 
Last edited:
Top