com.google.android.libraries.places.api.Places Java Examples
The following examples show how to use
com.google.android.libraries.places.api.Places.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProgrammaticAutocompleteToolbarActivity.java From android-places-demos with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Use whatever theme was set from the MainActivity - some of these colors (e.g primary color) // will get picked up by the AutocompleteActivity. int theme = getIntent().getIntExtra(MainActivity.THEME_RES_ID_EXTRA, 0); if (theme != 0) { setTheme(theme); } setContentView(R.layout.activity_programmatic_autocomplete); setSupportActionBar(findViewById(R.id.toolbar)); // Initialize members progressBar = findViewById(R.id.progress_bar); viewAnimator = findViewById(R.id.view_animator); placesClient = Places.createClient(this); queue = Volley.newRequestQueue(this); initRecyclerView(); }
Example #2
Source File: ProgrammaticAutocompleteToolbarActivity.java From android-places-demos with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Use whatever theme was set from the MainActivity - some of these colors (e.g primary color) // will get picked up by the AutocompleteActivity. int theme = getIntent().getIntExtra(MainActivity.THEME_RES_ID_EXTRA, 0); if (theme != 0) { setTheme(theme); } setContentView(R.layout.activity_programmatic_autocomplete); setSupportActionBar(findViewById(R.id.toolbar)); // Initialize members progressBar = findViewById(R.id.progress_bar); viewAnimator = findViewById(R.id.view_animator); placesClient = Places.createClient(this); queue = Volley.newRequestQueue(this); initRecyclerView(); }
Example #3
Source File: MapPresenter.java From ridesharing-android with MIT License | 6 votes |
public MapPresenter(Context context, V view, S state) { mContext = context.getApplicationContext() == null ? context : context.getApplicationContext(); mView = view; mState = state; mapPadding = mContext.getResources().getDimensionPixelSize(R.dimen.map_padding); Places.initialize(mContext, MainActivity.GOOGLE_API_KEY); mapConfig = MapUtils.getBuilder(context).build(); hyperTrackViews = HyperTrackViews.getInstance(mContext, HyperTrackUtils.getPubKey(context)); locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); db = FirebaseFirestore.getInstance(); List<Place.Field> fields = Arrays.asList( Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG, Place.Field.ADDRESS, Place.Field.ADDRESS_COMPONENTS ); autocompleteIntentBuilder = new Autocomplete.IntentBuilder( AutocompleteActivityMode.OVERLAY, fields); }
Example #4
Source File: MainActivity.java From android-places-demos with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String apiKey = getString(R.string.places_api_key); if (apiKey.equals("")) { Toast.makeText(this, getString(R.string.error_api_key), Toast.LENGTH_LONG).show(); return; } // Setup Places Client if (!Places.isInitialized()) { Places.initialize(getApplicationContext(), apiKey); } setLaunchActivityClickListener(R.id.programmatic_autocomplete_button, ProgrammaticAutocompleteToolbarActivity.class); setLaunchActivityClickListener(R.id.autocomplete_button, AutocompleteTestActivity.class); setLaunchActivityClickListener(R.id.place_and_photo_button, PlaceAndPhotoTestActivity.class); setLaunchActivityClickListener(R.id.current_place_button, CurrentPlaceTestActivity.class); widgetThemeSpinner = findViewById(R.id.theme_spinner); widgetThemeSpinner.setAdapter( new ArrayAdapter<>( /* context= */ this, android.R.layout.simple_list_item_1, Arrays.asList( "Default", "\uD83D\uDCA9 brown", "\uD83E\uDD2E green", "\uD83D\uDE08 purple"))); }
Example #5
Source File: CurrentPlaceTestActivity.java From android-places-demos with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Use whatever theme was set from the MainActivity. int theme = getIntent().getIntExtra(MainActivity.THEME_RES_ID_EXTRA, 0); if (theme != 0) { setTheme(theme); } setContentView(R.layout.current_place_test_activity); // Retrieve a PlacesClient (previously initialized - see MainActivity) placesClient = Places.createClient(this); // Set view objects List<Field> placeFields = FieldSelector.allExcept( Field.ADDRESS_COMPONENTS, Field.OPENING_HOURS, Field.PHONE_NUMBER, Field.UTC_OFFSET, Field.WEBSITE_URI); fieldSelector = new FieldSelector( findViewById(R.id.use_custom_fields), findViewById(R.id.custom_fields_list), placeFields, savedInstanceState); responseView = findViewById(R.id.response); setLoading(false); // Set listeners for programmatic Find Current Place findViewById(R.id.find_current_place_button).setOnClickListener((view) -> findCurrentPlace()); }
Example #6
Source File: MainActivity.java From android-places-demos with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String apiKey = getString(R.string.places_api_key); if (apiKey.equals("")) { Toast.makeText(this, getString(R.string.error_api_key), Toast.LENGTH_LONG).show(); return; } // Setup Places Client if (!Places.isInitialized()) { Places.initialize(getApplicationContext(), apiKey); } setLaunchActivityClickListener(R.id.programmatic_autocomplete_button, ProgrammaticAutocompleteToolbarActivity.class); setLaunchActivityClickListener(R.id.autocomplete_button, AutocompleteTestActivity.class); setLaunchActivityClickListener(R.id.place_and_photo_button, PlaceAndPhotoTestActivity.class); setLaunchActivityClickListener(R.id.current_place_button, CurrentPlaceTestActivity.class); widgetThemeSpinner = findViewById(R.id.theme_spinner); widgetThemeSpinner.setAdapter( new ArrayAdapter<>( /* context= */ this, android.R.layout.simple_list_item_1, Arrays.asList( "Default", "\uD83D\uDCA9 brown", "\uD83E\uDD2E green", "\uD83D\uDE08 purple"))); }
Example #7
Source File: CurrentPlaceTestActivity.java From android-places-demos with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Use whatever theme was set from the MainActivity. int theme = getIntent().getIntExtra(MainActivity.THEME_RES_ID_EXTRA, 0); if (theme != 0) { setTheme(theme); } setContentView(R.layout.current_place_test_activity); // Retrieve a PlacesClient (previously initialized - see MainActivity) placesClient = Places.createClient(this); // Set view objects List<Field> placeFields = FieldSelector.allExcept( Field.ADDRESS_COMPONENTS, Field.OPENING_HOURS, Field.PHONE_NUMBER, Field.UTC_OFFSET, Field.WEBSITE_URI); fieldSelector = new FieldSelector( findViewById(R.id.use_custom_fields), findViewById(R.id.custom_fields_list), placeFields, savedInstanceState); responseView = findViewById(R.id.response); setLoading(false); // Set listeners for programmatic Find Current Place findViewById(R.id.find_current_place_button).setOnClickListener((view) -> findCurrentPlace()); }
Example #8
Source File: GetStartedActivity.java From android-places-demos with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final String apiKey = "You API key"; // [START maps_places_get_started] // Initialize the SDK Places.initialize(getApplicationContext(), apiKey); // Create a new PlacesClient instance PlacesClient placesClient = Places.createClient(this); // [END maps_places_get_started] }
Example #9
Source File: PlaceAutocompleteActivity.java From android-places-demos with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final String apiKey = "You API key"; // [START maps_places_get_started] // Initialize the SDK Places.initialize(getApplicationContext(), apiKey); // Create a new PlacesClient instance PlacesClient placesClient = Places.createClient(this); // [END maps_places_get_started] }
Example #10
Source File: SearchPlacePresenter.java From live-app-android with MIT License | 5 votes |
public SearchPlacePresenter(Context context, View view) { this.context = context.getApplicationContext() == null ? context : context.getApplicationContext(); this.view = view; this.state = new SearchPlaceState(context); hyperTrack = HyperTrack.getInstance(context, state.getHyperTrackPubKey()); placesClient = Places.createClient(context); tripsManager = HTMobileClient.getTripsManager(context); }
Example #11
Source File: App.java From live-app-android with MIT License | 5 votes |
@Override public void onCreate() { super.onCreate(); HyperTrack.enableDebugLogging(); if (!Places.isInitialized()) { Places.initialize(getApplicationContext(), "AIzaSyBKZejrZNZpLlemrH28Nc46XzHsRSVRxKI"); } }
Example #12
Source File: MapsActivityCurrentPlace.java From android-samples with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // [START_EXCLUDE silent] // [START maps_current_place_on_create_save_instance_state] // Retrieve location and camera position from saved instance state. if (savedInstanceState != null) { lastKnownLocation = savedInstanceState.getParcelable(KEY_LOCATION); cameraPosition = savedInstanceState.getParcelable(KEY_CAMERA_POSITION); } // [END maps_current_place_on_create_save_instance_state] // [END_EXCLUDE] // Retrieve the content view that renders the map. setContentView(R.layout.activity_maps); // [START_EXCLUDE silent] // Construct a PlacesClient Places.initialize(getApplicationContext(), getString(R.string.maps_api_key)); placesClient = Places.createClient(this); // Construct a FusedLocationProviderClient. fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this); // Build the map. // [START maps_current_place_map_fragment] SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); // [END maps_current_place_map_fragment] // [END_EXCLUDE] }
Example #13
Source File: PlaceAndPhotoTestActivity.java From android-places-demos with Apache License 2.0 | 4 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Use whatever theme was set from the MainActivity. int theme = getIntent().getIntExtra(MainActivity.THEME_RES_ID_EXTRA, 0); if (theme != 0) { setTheme(theme); } setContentView(R.layout.place_and_photo_test_activity); // Retrieve a PlacesClient (previously initialized - see MainActivity) placesClient = Places.createClient(this); if (savedInstanceState != null) { photo = savedInstanceState.getParcelable(FETCHED_PHOTO_KEY); } // Set up view objects responseView = findViewById(R.id.response); photoView = findViewById(R.id.photo); CheckBox fetchPhotoCheckbox = findViewById(R.id.fetch_photo_checkbox); fetchPhotoCheckbox.setOnCheckedChangeListener( (buttonView, isChecked) -> setPhotoSizingEnabled(isChecked)); CheckBox customPhotoCheckbox = findViewById(R.id.use_custom_photo_reference); customPhotoCheckbox.setOnCheckedChangeListener( (buttonView, isChecked) -> setCustomPhotoReferenceEnabled(isChecked)); fieldSelector = new FieldSelector( findViewById(R.id.use_custom_fields), findViewById(R.id.custom_fields_list), savedInstanceState); // Set listeners for programmatic Fetch Place findViewById(R.id.fetch_place_and_photo_button).setOnClickListener(view -> fetchPlace()); // UI initialization setLoading(false); setPhotoSizingEnabled(fetchPhotoCheckbox.isChecked()); setCustomPhotoReferenceEnabled(customPhotoCheckbox.isChecked()); if (photo != null) { fetchPhoto(photo); } }
Example #14
Source File: AutocompleteTestActivity.java From android-places-demos with Apache License 2.0 | 4 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Use whatever theme was set from the MainActivity - some of these colors (e.g primary color) // will get picked up by the AutocompleteActivity. int theme = getIntent().getIntExtra(MainActivity.THEME_RES_ID_EXTRA, 0); if (theme != 0) { setTheme(theme); } setContentView(R.layout.autocomplete_test_activity); // Retrieve a PlacesClient (previously initialized - see MainActivity) placesClient = Places.createClient(this); // Set up view objects responseView = findViewById(R.id.response); Spinner typeFilterSpinner = findViewById(R.id.autocomplete_type_filter); typeFilterSpinner.setAdapter( new ArrayAdapter<>( this, android.R.layout.simple_list_item_1, Arrays.asList(TypeFilter.values()))); CheckBox useTypeFilterCheckBox = findViewById(R.id.autocomplete_use_type_filter); useTypeFilterCheckBox.setOnCheckedChangeListener( (buttonView, isChecked) -> typeFilterSpinner.setEnabled(isChecked)); fieldSelector = new FieldSelector( findViewById(R.id.use_custom_fields), findViewById(R.id.custom_fields_list), savedInstanceState); setupAutocompleteSupportFragment(); // Set listeners for Autocomplete activity findViewById(R.id.autocomplete_activity_button) .setOnClickListener(view -> startAutocompleteActivity()); // Set listeners for programmatic Autocomplete findViewById(R.id.fetch_autocomplete_predictions_button) .setOnClickListener(view -> findAutocompletePredictions()); // UI initialization setLoading(false); typeFilterSpinner.setEnabled(false); }
Example #15
Source File: PlaceAndPhotoTestActivity.java From android-places-demos with Apache License 2.0 | 4 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Use whatever theme was set from the MainActivity. int theme = getIntent().getIntExtra(MainActivity.THEME_RES_ID_EXTRA, 0); if (theme != 0) { setTheme(theme); } setContentView(R.layout.place_and_photo_test_activity); // Retrieve a PlacesClient (previously initialized - see MainActivity) placesClient = Places.createClient(this); if (savedInstanceState != null) { photo = savedInstanceState.getParcelable(FETCHED_PHOTO_KEY); } // Set up view objects responseView = findViewById(R.id.response); photoView = findViewById(R.id.photo); CheckBox fetchPhotoCheckbox = findViewById(R.id.fetch_photo_checkbox); fetchPhotoCheckbox.setOnCheckedChangeListener( (buttonView, isChecked) -> setPhotoSizingEnabled(isChecked)); CheckBox customPhotoCheckbox = findViewById(R.id.use_custom_photo_reference); customPhotoCheckbox.setOnCheckedChangeListener( (buttonView, isChecked) -> setCustomPhotoReferenceEnabled(isChecked)); fieldSelector = new FieldSelector( findViewById(R.id.use_custom_fields), findViewById(R.id.custom_fields_list), savedInstanceState); // Set listeners for programmatic Fetch Place findViewById(R.id.fetch_place_and_photo_button).setOnClickListener(view -> fetchPlace()); // UI initialization setLoading(false); setPhotoSizingEnabled(fetchPhotoCheckbox.isChecked()); setCustomPhotoReferenceEnabled(customPhotoCheckbox.isChecked()); if (photo != null) { fetchPhoto(photo); } }
Example #16
Source File: AutocompleteTestActivity.java From android-places-demos with Apache License 2.0 | 4 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Use whatever theme was set from the MainActivity - some of these colors (e.g primary color) // will get picked up by the AutocompleteActivity. int theme = getIntent().getIntExtra(MainActivity.THEME_RES_ID_EXTRA, 0); if (theme != 0) { setTheme(theme); } setContentView(R.layout.autocomplete_test_activity); // Retrieve a PlacesClient (previously initialized - see MainActivity) placesClient = Places.createClient(this); // Set up view objects responseView = findViewById(R.id.response); Spinner typeFilterSpinner = findViewById(R.id.autocomplete_type_filter); typeFilterSpinner.setAdapter( new ArrayAdapter<>( this, android.R.layout.simple_list_item_1, Arrays.asList(TypeFilter.values()))); CheckBox useTypeFilterCheckBox = findViewById(R.id.autocomplete_use_type_filter); useTypeFilterCheckBox.setOnCheckedChangeListener( (buttonView, isChecked) -> typeFilterSpinner.setEnabled(isChecked)); fieldSelector = new FieldSelector( findViewById(R.id.use_custom_fields), findViewById(R.id.custom_fields_list), savedInstanceState); setupAutocompleteSupportFragment(); // Set listeners for Autocomplete activity findViewById(R.id.autocomplete_activity_button) .setOnClickListener(view -> startAutocompleteActivity()); // Set listeners for programmatic Autocomplete findViewById(R.id.fetch_autocomplete_predictions_button) .setOnClickListener(view -> findAutocompletePredictions()); // UI initialization setLoading(false); typeFilterSpinner.setEnabled(false); }