B4A Class [B4X] [custom view] Google Place Autocomplete View

Erel

Administrator
Staff member
Licensed User
B4A, B4i and B4J classes are attached.

PlacesAutocompleteView is based on SearchView. It calls Google's Places autocomplete API to let the user select a place.

Once selected it sends another request to get the exact location. You can get other information as well.



B4A project depends on: B4A v7+, IME, JSON and OkHttpUtils2
B4i project depends on: B4i v4+, iHttpUtils2, iJSON and iUI8.

- In order to use Google Places API you need to create a project in Google developer console: https://console.developers.google.com/
- Enable Google Places API Web Service api.
- Create an API key and set it in Main.Process_Globals.

Make sure to go over Google's policies: https://developers.google.com/places/web-service/policies#logo_requirements
The usage limits for a free unidentified account are quite low. Once identified the limits are much higher.
 

Attachments

Last edited:

DonManfred

Expert
Licensed User
for me not works for you ?
i did not tried it... But i guess you forget to
- In order to use Google Places API you need to create a project in Google developer console: https://console.developers.google.com/
- Enable Google Places API Web Service api.
- Create an API key and set it in Main.Process_Globals.
maybe you api-key is not bound to use the Google Places Api Web Service?

I´ll check the example this evening. But i´m pretty sure it will work if i setup everything correctly.

plces_005.jpg
 

Csaba Balogh

Member
Licensed User
How can I get postcodes (ZIP codes ) listed within the result? It is necessary since lot of cities have the same street name with different postal codes. I was trying hard to find out from google's api documentation, but it seems to be very condusing at the moment. Any ideas?
 
Last edited:

roerGarcia

Member
Licensed User
From https://developers.google.com/place...aries/places/api/model/Place.Type#POSTAL_CODE

public static final Place.Type POSTAL_CODE
public static final Place.Type POSTAL_CODE_PREFIX
public static final Place.Type POSTAL_CODE_SUFFIX
public static final Place.Type POSTAL_TOWN
public static final Place.Type POST_BOX
public static final Place.Type POST_OFFICE


And

Place types
You may restrict results from a Place Autocomplete request to be of a certain type by passing a types parameter. The parameter specifies a type or a type collection, as listed in the supported types below. If nothing is specified, all types are returned. In general only a single type is allowed. The exception is that you can safely mix the geocode and establishment types, but note that this will have the same effect as specifying no types. The supported types are:

the (regions) type collection instructs the Places service to return any result matching the following types:
  • locality
  • sublocality
  • postal_code
From https://developers.google.com/places/web-service/autocomplete#place_types

Shalom.
 
Last edited:

yfleury

Active Member
Licensed User
I find my self... Maybe I am better programmer day after day

I modify PlacesAutocompleteView.bas file at line 83 and 84 and it work. Is it a good try?
B4X:
j.Download2("https://maps.googleapis.com/maps/api/place/autocomplete/json", _
  Array As String("input", New, "key", Main.API_KEY, "locationbias", "circle:100000@" & latitudeGPS & "," & longitudeGPS))
 

Mark Ryan Penafiel

Member
Licensed User
Yes i saw the raduis in the documentation, i also saw country but could not find an example. I guess raduis will do for now.thanks for the replies
 
Top