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

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.

SS-2017-07-23_16.09.25.png
SS-2017-07-23_16.10.07.png


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

  • B4A_GooglePlacesAutocomplete.zip
    12.5 KB · Views: 956
  • B4i_GooglePlacesAutocomplete.zip
    8.9 KB · Views: 566
  • B4J_GooglePlacesAutocomplete.zip
    5.9 KB · Views: 578
Last edited:

Magma

Expert
Licensed User
Longtime User
@Erel why b4j class not working. I using my api key... but when typing the list extends or being small without anything in... ?

this class is exactly what i need for Addresses... seems that must have limits and bounds if works
 

DonManfred

Expert
Licensed User
Longtime 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

Active Member
Licensed User
Longtime 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
Longtime 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
Longtime 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