Java Code Examples for com.google.android.gms.location.places.ui.PlacePicker#getPlace()
The following examples show how to use
com.google.android.gms.location.places.ui.PlacePicker#getPlace() .
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: MapsActivity.java From io2015-codelabs with Apache License 2.0 | 6 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_PLACE_PICKER) { if (resultCode == Activity.RESULT_OK) { Place place = PlacePicker.getPlace(data, this); Map<String, Object> checkoutData = new HashMap<>(); checkoutData.put("time", ServerValue.TIMESTAMP); mFirebase.child(FIREBASE_ROOT_NODE).child(place.getId()).setValue(checkoutData); } else if (resultCode == PlacePicker.RESULT_ERROR) { Toast.makeText(this, "Places API failure! Check the API is enabled for your key", Toast.LENGTH_LONG).show(); } } else { super.onActivityResult(requestCode, resultCode, data); } }
Example 2
Source File: ChatActivity.java From NaviBee with GNU General Public License v3.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == PLACE_PICKER_REQUEST) { if (resultCode == RESULT_OK) { PlacePicker.getLatLngBounds(data); Place place = PlacePicker.getPlace(this, data); conversation.sendLocation(place.getLatLng().latitude, place.getLatLng().longitude); } } }
Example 3
Source File: EventEditActivity.java From NaviBee with GNU General Public License v3.0 | 5 votes |
public void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); // select friend feedback switch (requestCode) { case SELECT_FRIEND_REQUEST: if(resultCode == RESULT_OK) { selectedUsers = (HashMap<String, UserInfoManager.UserInfo>) intent.getSerializableExtra("selected"); // show chips result setChipGroupView(selectedUsers); } break; case IMAGE_REVIEW_REQUEST: if(resultCode == RESULT_OK) { Boolean isDeleted = intent.getBooleanExtra("isDeleted", false); int position = intent.getIntExtra("position", -1); if(isDeleted){ pics.remove(position); picsUri.remove(position); picsUpdate(); } } break; case PLACE_PICKER_REQUEST: if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(this, intent); String placeName = getPlaceDisplayName(place); locationField.setText(placeName); eventLocation = place; } break; } }
Example 4
Source File: ViewActivity.java From memoir with Apache License 2.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == PLACE_PICKER_REQUEST && resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(this, data); note.setLocation(place); refreshLayout(); } else if (requestCode == EDIT_BODY_REQUEST && resultCode == RESULT_OK) { note.body = data.getStringExtra(EditActivity.NOTE_BODY_KEY); refreshLayout(); } }
Example 5
Source File: SearchActivity.java From Car-Pooling with MIT License | 5 votes |
/** * This method is used to get lpickup location from maps and set it to address * @param requestCode request code * @param resultCode result code * @param data data fetched */ public void onActivityResult(int requestCode,int resultCode, Intent data){ if(requestCode == PLACE_PICKER_REQUEST) { if(resultCode==RESULT_OK){ Place place = PlacePicker.getPlace(data, this); address = String.format("Pickup Location: %s", place.getAddress()); get_place.setText(address); setAddress(address); } } }
Example 6
Source File: SettingsActivity.java From Advanced_Android_Development with Apache License 2.0 | 4 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Check to see if the result is from our Place Picker intent if (requestCode == PLACE_PICKER_REQUEST) { // Make sure the request was successful if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(data, this); String address = place.getAddress().toString(); LatLng latLong = place.getLatLng(); // If the provided place doesn't have an address, we'll form a display-friendly // string from the latlng values. if (TextUtils.isEmpty(address)) { address = String.format("(%.2f, %.2f)",latLong.latitude, latLong.longitude); } SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(getString(R.string.pref_location_key), address); // Also store the latitude and longitude so that we can use these to get a precise // result from our weather service. We cannot expect the weather service to // understand addresses that Google formats. editor.putFloat(getString(R.string.pref_location_latitude), (float) latLong.latitude); editor.putFloat(getString(R.string.pref_location_longitude), (float) latLong.longitude); editor.commit(); // Tell the SyncAdapter that we've changed the location, so that we can update // our UI with new values. We need to do this manually because we are responding // to the PlacePicker widget result here instead of allowing the // LocationEditTextPreference to handle these changes and invoke our callbacks. Preference locationPreference = findPreference(getString(R.string.pref_location_key)); setPreferenceSummary(locationPreference, address); // Add attributions for our new PlacePicker location. if (mAttribution != null) { mAttribution.setVisibility(View.VISIBLE); } else { // For pre-Honeycomb devices, we cannot add a footer, so we will use a snackbar View rootView = findViewById(android.R.id.content); Snackbar.make(rootView, getString(R.string.attribution_text), Snackbar.LENGTH_LONG).show(); } Utility.resetLocationStatus(this); SunshineSyncAdapter.syncImmediately(this); } } else { super.onActivityResult(requestCode, resultCode, data); } }
Example 7
Source File: SettingsFragment.java From BackPackTrackII with GNU General Public License v3.0 | 4 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == ACTIVITY_PICKPLACE && resultCode == Activity.RESULT_OK) { Place place = PlacePicker.getPlace(getActivity(), data); final CharSequence name = place.getName(); LatLng ll = place.getLatLng(); if (name == null || ll == null) return; // Build location final Location location = new Location("place"); location.setLatitude(ll.latitude); location.setLongitude(ll.longitude); location.setTime(System.currentTimeMillis()); // Get settings SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); final boolean altitude_waypoint = prefs.getBoolean(PREF_ALTITUDE_WAYPOINT, DEFAULT_ALTITUDE_WAYPOINT); new AsyncTask<Object, Object, Object>() { protected Object doInBackground(Object... params) { int altitude_type = (location.hasAltitude() ? BackgroundService.ALTITUDE_GPS : BackgroundService.ALTITUDE_NONE); // Add elevation data if (!location.hasAltitude() && Util.isConnected(getActivity())) { if (altitude_waypoint) try { GoogleElevationApi.getElevation(location, getActivity()); altitude_type = BackgroundService.ALTITUDE_LOOKUP; } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } } if (altitude_type != BackgroundService.ALTITUDE_NONE) altitude_type |= BackgroundService.ALTITUDE_KEEP; // Persist location new DatabaseHelper(getActivity()).insertLocation(location, altitude_type, name.toString()).close(); return null; } @Override protected void onPostExecute(Object result) { if (running) Toast.makeText(getActivity(), getString(R.string.msg_added, name.toString()), Toast.LENGTH_SHORT).show(); } }.execute(); } else if (requestCode == ACTIVITY_PLAY_SERVICES) ; // Do nothing else super.onActivityResult(requestCode, resultCode, data); }
Example 8
Source File: PlacePickerFragment.java From android-play-places with Apache License 2.0 | 4 votes |
/** * Extracts data from PlacePicker result. * This method is called when an Intent has been started by calling * {@link #startActivityForResult(android.content.Intent, int)}. The Intent for the * {@link com.google.android.gms.location.places.ui.PlacePicker} is started with * {@link #REQUEST_PLACE_PICKER} request code. When a result with this request code is received * in this method, its data is extracted by converting the Intent data to a {@link Place} * through the * {@link com.google.android.gms.location.places.ui.PlacePicker#getPlace(android.content.Intent, * android.content.Context)} call. * * @param requestCode * @param resultCode * @param data */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // BEGIN_INCLUDE(activity_result) if (requestCode == REQUEST_PLACE_PICKER) { // This result is from the PlacePicker dialog. // Enable the picker option showPickAction(true); if (resultCode == Activity.RESULT_OK) { /* User has picked a place, extract data. Data is extracted from the returned intent by retrieving a Place object from the PlacePicker. */ final Place place = PlacePicker.getPlace(data, getActivity()); /* A Place object contains details about that place, such as its name, address and phone number. Extract the name, address, phone number, place ID and place types. */ final CharSequence name = place.getName(); final CharSequence address = place.getAddress(); final CharSequence phone = place.getPhoneNumber(); final String placeId = place.getId(); String attribution = PlacePicker.getAttributions(data); if(attribution == null){ attribution = ""; } // Update data on card. getCardStream().getCard(CARD_DETAIL) .setTitle(name.toString()) .setDescription(getString(R.string.detail_text, placeId, address, phone, attribution)); // Print data to debug log Log.d(TAG, "Place selected: " + placeId + " (" + name.toString() + ")"); // Show the card. getCardStream().showCard(CARD_DETAIL); } else { // User has not selected a place, hide the card. getCardStream().hideCard(CARD_DETAIL); } } else { super.onActivityResult(requestCode, resultCode, data); } // END_INCLUDE(activity_result) }