B4A Class TPlacesDetail

Hi,

This is a class for getting place name (name of building, plaza, mall, tower, etc.) from Google Places API. Place is identified using Place ID which can be retrieved for example in geocoding result from Google Geocoding API. I use this class in my app BS Where Am I .

Perhaps anyone want to use this class. It uses HttpUtils2 and JSON libraries.

It is a simple code, but it's just enough for my current need. You may use, modify, or distribute anyway you want. If would be great if you inform me for any enhancement.


Cheers,
 

Attachments

  • TPlacesDetail.bas
    3.4 KB · Views: 168
Last edited:

Xenno

Member
Licensed User
Public Methods

Initialize
It is for initializing the object. Parent is caller module name. Note: API Key is required. Get it from Google Places API.
B4X:
Public Sub Initialize(prmParent As Object, prmEventName As String, prmAPIKey As String)

getPlaceId
Get current Place ID; available after calling GetPlaceNameFromId.
B4X:
Sub getPlaceId As String

GetPlaceNameFromId
Get place name based on a Place ID. The result event are [eventname]_OnSuccess and [eventname]_OnError. Parent module needs to declare these routines.
B4X:
Sub GetPlaceNameFromId(prmPlaceId As String)
 

Xenno

Member
Licensed User
Short Example

Preparing the object as usual.
B4X:
Dim mPlaces As TPlacesDetail
...
mPlaces.Initialize(Me, "mPlaces", kPlaceAPIKey)
Replace kPlaceAPIKey with your own key.

Write two subroutines for events.
B4X:
Sub mPlaces_OnSuccess(prmPlaceName As String)
    Log("Place name: " & prmPlaceName)
End Sub

Sub mPlaces_OnError(prmMsg As String)
    Log(prmMsg)
End Sub

Get the Place ID from geocoding event then call GetPlaceNameFromId of mPlaces object.
B4X:
Dim results As List
Dim oneResult As Map

results = json.Get("results")
If (results.Size > 0) Then
    oneResult = results.Get(0)
    ....                       
    placeId = oneResult.Get("place_id")    
    mPlaces.GetPlaceNameFromId(mPlaceId)       
Else
    Log("Could not resolve address")
End If
 

LucaMs

Expert
Licensed User
Longtime User
1) I've never "played" with Google maps but... why not display them too?
2) from your app: "Are you lost?". Well, your app does not work well, because "I'm lost" but it is not able to say me where I am :p
 

Xenno

Member
Licensed User
1) I've never "played" with Google maps but... why not display them too?
2) from your app: "Are you lost?". Well, your app does not work well, because "I'm lost" but it is not able to say me where I am :p
Hello, LucaMs
  1. Displaying map requires loading time and processing. BS Where Am I is intended to be quick and simple.
  2. I'm sorry that the app does not work well for you. I use it daily; getting know my position while at the same time testing the app. The widget is my handy tool to quickly get the information.
Thank you for your comment and input. I will look at my code.

Anyway, this thread is focused on TPlacesDetail. So, please understand I can't discuss further about BS Where Am I here.


Cheers,
 
Last edited:
Top