@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1) { if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(data, this); Intent intent = new Intent(this, InfoActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("name", place.getName()); intent.putExtra("lat", place.getLatLng().latitude); intent.putExtra("lng", place.getLatLng().longitude); startActivity(intent); finish(); } else finish(); } }
/*** * Called when the Place Picker Activity returns back with a selected place (or after canceling) * * @param requestCode The request code passed when calling startActivityForResult * @param resultCode The result code specified by the second activity * @param data The Intent that carries the result data. */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode==PLACE_PICKER_REQUEST&&resultCode==RESULT_OK){ Place place = PlacePicker.getPlace(this,data); if (place==null){ Log.i(LOG_TAG,"No place selected"); return; } String placeName = place.getName().toString(); String placeAddress = place.getAddress().toString(); String placeId = place.getId(); ContentValues values = new ContentValues(); values.put(PlacesContract.PlaceEntry.COLUMN_PLACE_ID,placeId); getContentResolver().insert(PlacesContract.PlaceEntry.CONTENT_URI,values); refreshPlacesData(); } }
/** * Set current location from map * TODO: Faire mieux la difference entre une location exacte et une * * @param location the location returned from the map picker */ public void setCurrentLocation(Intent data) { final Place place = PlacePicker.getPlace(getActivity(), data); Geocoder geocoder = new Geocoder(getActivity()); try { List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1); elephant.currentLoc.cityName = addresses.get(0).getAddressLine(0); if (!addresses.get(0).getAddressLine(0).equals(addresses.get(0).getSubAdminArea())) { elephant.currentLoc.districtName = addresses.get(0).getSubAdminArea(); } elephant.currentLoc.provinceName = addresses.get(0).getAdminArea(); } catch (IOException e) { e.printStackTrace(); } currentLocation.setText(elephant.currentLoc.format()); }
/** * Set birth location from map * * @param location the location returned from the map picker */ public void setBirthLocation(Intent data) { final Place place = PlacePicker.getPlace(getActivity(), data); Geocoder geocoder = new Geocoder(getActivity()); try { List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1); elephant.birthLoc.cityName = addresses.get(0).getAddressLine(0); if (!addresses.get(0).getAddressLine(0).equals(addresses.get(0).getSubAdminArea())) { elephant.birthLoc.districtName = addresses.get(0).getSubAdminArea(); } elephant.birthLoc.provinceName = addresses.get(0).getAdminArea(); } catch (IOException e) { e.printStackTrace(); } birthLocation.setText(elephant.birthLoc.format()); }
public void setRegistrationLocation(Intent data) { final Place place = PlacePicker.getPlace(getActivity(), data); Geocoder geocoder = new Geocoder(getActivity()); try { List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1); elephant.registrationLoc.cityName = addresses.get(0).getAddressLine(0); if (!addresses.get(0).getAddressLine(0).equals(addresses.get(0).getSubAdminArea())) { elephant.registrationLoc.districtName = addresses.get(0).getSubAdminArea(); } elephant.registrationLoc.provinceName = addresses.get(0).getAdminArea(); } catch (IOException e) { e.printStackTrace(); } registrationLocation.setText(elephant.registrationLoc.format()); }
@OnClick(R.id.reminder_item_waypoint_title_text_view) public void onWaypointTitleClick() { PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); if (mRemindItem.getWaypoint() != null) { LocationPoint locationPoint = mRemindItem.getWaypoint().getLocation(); LatLng latLng = new LatLng(locationPoint.getLatitude(), locationPoint.getLongitude()); LatLngBounds latLngBounds = new LatLngBounds(latLng, latLng); builder.setLatLngBounds(latLngBounds); } Intent intent = null; try { intent = builder.build(getActivity()); } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) { e.printStackTrace(); } mProgressDialog = ProgressDialog.show(mContext, getString(R.string.reminder_place_picker_progress_dialog_title), getString(R.string.reminder_place_picker_progress_dialog_message), true, false); startActivityForResult(intent, PLACE_PICKER_REQUEST); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_LOCATION) { final LocationSettingsStates states = LocationSettingsStates.fromIntent(data); if (resultCode == Activity.RESULT_OK) { Toast.makeText(getApplicationContext(), R.string.location_enabled, Toast.LENGTH_LONG).show(); startLocationUpdates(); } else { Toast.makeText(getApplicationContext(), "Loc is still off,", Toast.LENGTH_LONG).show(); } } else if (requestCode == PLACE_PICKER_REQUEST) { if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(data, this); double lat = place.getLatLng().latitude; double lon = place.getLatLng().longitude; setMyLocationToSharePref((float) lat, (float) lon); setMyAddress(this, place.getAddress().toString()); Location newLoc = new Location(""); newLoc.setLatitude(lat); newLoc.setLongitude(lon); EventBus.getDefault().post(newLoc); } } }
public void onActivityResult(final Activity activity, final int requestCode, final int resultCode, final Intent data) { if (mCallback == null || requestCode != REQUEST_PLACE_PICKER) { return; } response = Arguments.createMap(); if (resultCode == 2) { response.putString("error", "Google Maps not setup correctly. Did you forget the API key, or enabling the Places API for Android?"); mCallback.invoke(response); } else if (resultCode == Activity.RESULT_OK) { final Place place = PlacePicker.getPlace(data, reactContext); final CharSequence address = place.getAddress(); final LatLng coordinate = place.getLatLng(); final CharSequence name = place.getName(); final CharSequence id = place.getId(); response.putString("address", address.toString()); response.putDouble("latitude", coordinate.latitude); response.putDouble("longitude", coordinate.longitude); response.putString("name", name.toString()); response.putString("google_id", id.toString()); mCallback.invoke(response); } else { response.putBoolean("didCancel", true); mCallback.invoke(response); return; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_place_picker); mName = (TextView) findViewById(R.id.textView); mAddress = (TextView) findViewById(R.id.textView2); mAttributions = (TextView) findViewById(R.id.textView3); Button pickerButton = (Button) findViewById(R.id.pickerButton); pickerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder(); intentBuilder.setLatLngBounds(BOUNDS_MOUNTAIN_VIEW); Intent intent = intentBuilder.build(PlacePickerActivity.this); startActivityForResult(intent, PLACE_PICKER_REQUEST); } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) { e.printStackTrace(); } } }); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_PICKER_REQUEST && resultCode == Activity.RESULT_OK) { final Place place = PlacePicker.getPlace(this, data); final CharSequence name = place.getName(); final CharSequence address = place.getAddress(); String attributions = (String) place.getAttributions(); if (attributions == null) { attributions = ""; } mName.setText(name); mAddress.setText(address); mAttributions.setText(Html.fromHtml(attributions)); } else { super.onActivityResult(requestCode, resultCode, data); } }
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_PICKER_REQUEST) { if (resultCode == RESULT_OK) { place = PlacePicker.getPlace(this, data); String toastMsg = getString(R.string.location_set); Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show(); Bid acceptedBid = myBook.getBid(bidPosition); acceptedBid.setLatitude(place.getLatLng().latitude); acceptedBid.setLongitude(place.getLatLng().longitude); myBook.deleteBids(); myBook.setStatus(Book.Status.BORROWED); myBook.addBid(acceptedBid); ESController.EditBookTask editBookTask = new ESController.EditBookTask(); editBookTask.execute(myBook); finish(); } } }
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_PICKER_REQUEST) { if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(this, data); try { stationSelected = new Station(place); inputStation.setText(place.getName()); } catch (IllegalArgumentException e) { String toastMsg = String.format("Ops, parece que %s não é um posto. Tente novamente.", place.getName()); Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show(); } } } }
/** * Pick place * https://medium.com/@hitherejoe/exploring-play-services-place-picker-autocomplete-150809f739fe */ @Override public void onPickEventPlaceClick() { PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder(); if(editEventDataModel.getEvent().hasLocation()) { double longitude = editEventDataModel.getEvent().getLongitude(); double latitude = editEventDataModel.getEvent().getLatitude(); double offset = 0.01; LatLng southwest = new LatLng(latitude - offset, longitude - offset); LatLng northeast = new LatLng(latitude + offset, longitude + offset); intentBuilder.setLatLngBounds(new LatLngBounds(southwest, northeast)); } try { startActivityForResult(intentBuilder.build(this), PLACE_PICKER_REQUEST_CODE); } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) { e.printStackTrace(); Toast.makeText(this, getString(R.string.unknown_error), Toast.LENGTH_LONG).show(); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_PLACE_PICKER) { // This result is from the PlacePicker dialog. if (resultCode == Activity.RESULT_OK) { // retrieve latitude and longitude from result data final Place place = PlacePicker.getPlace(data, this); LatLng latLng = place.getLatLng(); Log.i(TAG, "Lat: " + latLng.latitude + " Lon: " + latLng.longitude); onLocationPicked(latLng); } } else if (requestCode == REQUEST_RESOLVE_ERROR) { // This result is from the google play services error resolution intent resolvingError = false; if (resultCode == RESULT_OK) { Snackbar.make(snackbarCoordinator, R.string.resolution_successful, Snackbar.LENGTH_LONG).show(); } } else { super.onActivityResult(requestCode, resultCode, data); } }
/** * Retrieves the selected place from the place picker. */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_PICKER_REQUEST) { if (resultCode == RESULT_OK) { mPickedPlace = PlacePicker.getPlace(this, data); } else { mPickedPlace = null; } // Display the address of the selected place. CharSequence placeText = (mPickedPlace == null) ? getString(R.string.add_event_no_place_selected) : mPickedPlace.getAddress(); ((TextView) findViewById(R.id.picked_place_address)).setText(placeText); } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // The user has selected a place. Extract the location if (requestCode == REQUEST_PLACE_PICKER && resultCode == Activity.RESULT_OK) { Place place = PlacePicker.getPlace(data, getActivity()); Location l = new Location("placePicker"); l.setLatitude(place.getLatLng().latitude); l.setLongitude(place.getLatLng().longitude); specifiedLocation = l; btn_join.setEnabled(true); //loadLocationLayout.setVisibility(View.VISIBLE); } else { super.onActivityResult(requestCode, resultCode, data); } }
@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); } }
@SuppressLint("CommitPrefEdits") @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_SIGNUP) { if(resultCode == RESULT_CANCELED){ finish(); }else{ checkStartup(); } }if (requestCode == REQUEST_TUTORIAL){ m_preferences.edit().putBoolean(Constants.PREFERENCE_SHOWN_TUTORIAL,true).commit(); checkStartup(); } else if (requestCode == REQUEST_PLACE_PICKER) { if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(data, this); if(m_createFragment != null) m_createFragment.onPlacesSelected(new OnPlacesSelectedEvent(place,PlacePicker.getAttributions(data))); // m_eventBus.post(new OnPlacesSelectedEvent(place,PlacePicker.getAttributions(data))); } } }
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_PICKER_REQUEST) { if (resultCode == RESULT_OK) { Place selectedPlace = PlacePicker.getPlace(data, this); savePlace(selectedPlace); } } }
protected void onActivityResult(int requestCode, int resultCode, Intent data) { try { if (requestCode == REQUEST_CODE_PICKER && resultCode == RESULT_OK && data != null) { ArrayList<Image> dat = data.getParcelableArrayListExtra(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES); renderViewImage(dat); } else if (requestCode == PLACE_PICKER_REQUEST) { if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(AddActivity.this, data); String placename = String.format("%s", place.getName()); latitude = place.getLatLng().latitude; longitude = place.getLatLng().longitude; location_name.setText("" + placename); Toast.makeText(AddActivity.this, "You Select: " + placename, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "You Haven't Select Any Places", Toast.LENGTH_LONG).show(); } } } catch (Exception e) { Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show(); Log.d("Additem_Activity", "onActivityResult: " + e); } }
public static void selectLocation(Activity activity, int requestCode) { try { activity.startActivityForResult(new PlacePicker.IntentBuilder().build(activity), requestCode); } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) { Log.w(TAG, e); } }
public void pickLocationClicked(View view) { try { PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST); } catch (Exception e) { Toast.makeText(getApplicationContext(), "Play services not available.", Toast.LENGTH_SHORT).show(); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == PLACE_PICKER_REQUEST) { if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(this, intent); Location location = new Location(""); location.setLatitude(place.getLatLng().latitude); location.setLongitude(place.getLatLng().longitude); updateHomeLocationText(location); } } }
@Override protected View onCreateView(ViewGroup parent) { View view = super.onCreateView(parent); View currentLocation = view.findViewById(R.id.current_location); currentLocation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Context context = getContext(); // Launch the Place Picker so that the user can specify their location, and then // return the result to SettingsActivity. PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); // We are in a view right now, not an activity. So we need to get ourselves // an activity that we can use to start our Place Picker intent. By using // SettingsActivity in this way, we can ensure the result of the Place Picker // intent comes to the right place for us to process it. Activity settingsActivity = (SettingsActivity) context; try { settingsActivity.startActivityForResult( builder.build(context), SettingsActivity.PLACE_PICKER_REQUEST); } catch (GooglePlayServicesNotAvailableException | GooglePlayServicesRepairableException e) { // What did you do?? This is why we check Google Play services in onResume!!! // The difference in these exception types is the difference between pausing // for a moment to prompt the user to update/install/enable Play services vs // complete and utter failure. // If you prefer to manage Google Play services dynamically, then you can do so // by responding to these exceptions in the right moment. But I prefer a cleaner // user experience, which is why you check all of this when the app resumes, // and then disable/enable features based on that availability. } } }); return view; }
private void locationPlacesIntent() { try { PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); startActivityForResult(builder.build(getActivity()), PLACE_PICKER_REQUEST); } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) { e.printStackTrace(); } }
private void locationPlacesIntent() { try { PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST); } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) { e.printStackTrace(); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { StorageReference storageRef = storage.getReferenceFromUrl(Utils.URL_STORAGE_REFERENCE).child(Utils.FOLDER_STORAGE_IMG); if (requestCode == IMAGE_GALLERY_REQUEST) { if (resultCode == RESULT_OK) { Uri selectedImageUri = data.getData(); if (selectedImageUri != null) { sendFileFirebase(storageRef, selectedImageUri); } } } else if (requestCode == IMAGE_CAMERA_REQUEST) { if (resultCode == RESULT_OK) { if (filePathImageCamera != null && filePathImageCamera.exists()) { StorageReference imageCameraRef = storageRef.child(filePathImageCamera.getName() + "_camera"); sendFileFirebase(imageCameraRef, filePathImageCamera); } } } else if (requestCode == PLACE_PICKER_REQUEST) { if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(this, data); if (place != null) { LatLng latLng = place.getLatLng(); MapModel mapModel = new MapModel(latLng.latitude + "", latLng.longitude + ""); ChatModel chatModel = new ChatModel(userModel, Calendar.getInstance().getTime().getTime() + "", mapModel); mFirebaseDatabaseReference.child(room).push().setValue(chatModel); } } } }
/** * Obter local do usuario */ private void locationPlacesIntent() { try { PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST); } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) { e.printStackTrace(); } }
private void showLocationPicker(int resultCode) { PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); LatLng burmaNorth = new LatLng(16.193669, 95.229859); LatLng burmaSouth = new LatLng(28.279449, 97.576320); LatLngBounds bound = new LatLngBounds(burmaNorth, burmaSouth); builder.setLatLngBounds(bound); try { activity.startActivityForResult(builder.build(activity), resultCode); } catch (Exception e) { Log.e(TAG, e.getMessage()); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // menangkap hasil balikan dari Place Picker, dan menampilkannya pada TextView if (requestCode == PLACE_PICKER_REQUEST) { if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(data, this); String toastMsg = String.format( "Place: %s \n" + "Alamat: %s \n" + "Latlng %s \n", place.getName(), place.getAddress(), place.getLatLng().latitude+" "+place.getLatLng().longitude); tvPlaceAPI.setText(toastMsg); } } }
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_PICKER_REQUEST) { if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(data, this); String toastMsg = String.format("Place: %s", place.getName()); Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show(); location = place.getLatLng(); title.setText(place.getName()); } else { finish(); } } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_PLACE_PICKER) { if (resultCode == Activity.RESULT_OK) { Place place = PlacePicker.getPlace(this,data); Map<String,Object>shareLocation=new HashMap<>(); shareLocation.put("time", ServerValue.TIMESTAMP); //get data from Login Activity Intent in=getIntent(); Bundle b=in.getExtras(); String name=b.getString("name"); Long number=b.getLong("contact_no"); Toast.makeText(this,"name: "+name+" number: "+number.toString(),Toast.LENGTH_SHORT).show(); //Map<String,Long>userData=new HashMap<>(); //userData.put(name,number); Map userData=new HashMap(); userData.put(name,number); mFirebase.child(FIREBASE_ROOT_NODE).child(place.getId()).setValue(shareLocation); Firebase fire=new Firebase(FIREBASE_URL); Firebase userRef=fire.child(FIREBASE_ROOT_NODE); Firebase people=userRef.child(place.getId()); people.updateChildren(userData); //mFirebase.child(FIREBASE_ROOT_NODE).child(place.getId()); //mFirebase.setValue(userData); Toast.makeText(this,"added:"+name+" "+number,Toast.LENGTH_SHORT).show(); //Toast.makeText(this,"added location",Toast.LENGTH_SHORT).show(); } else if (resultCode == PlacePicker.RESULT_ERROR) { Toast.makeText(this, "Places API failure! Check that the API is enabled for your key", Toast.LENGTH_LONG).show(); } } else { super.onActivityResult(requestCode, resultCode, data); } }
@Override protected View onCreateView(ViewGroup parent) { View view = super.onCreateView(parent); View currentLocation = view.findViewById(R.id.current_location); currentLocation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Context context = getContext(); // Launch the Place Picker so that the user can specify their location, and then // return the result to SettingsActivity. PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); // We are in a view right now, not an activity. So we need to get ourselves // an activity that we can use to start our Place Picker intent. By using // SettingsActivity in this way, we can ensure the result of the Place Picker // intent comes to the right place for us to process it. Activity settingsActivity = (SettingsActivity) context; try { settingsActivity.startActivityForResult( builder.build(settingsActivity), SettingsActivity.PLACE_PICKER_REQUEST); } catch (GooglePlayServicesNotAvailableException | GooglePlayServicesRepairableException e) { // What did you do?? This is why we check Google Play services in onResume!!! // The difference in these exception types is the difference between pausing // for a moment to prompt the user to update/install/enable Play services vs // complete and utter failure. // If you prefer to manage Google Play services dynamically, then you can do so // by responding to these exceptions in the right moment. But I prefer a cleaner // user experience, which is why you check all of this when the app resumes, // and then disable/enable features based on that availability. } } }); return view; }
private void loadAddNewPrivyActivity() { if (checkIfLoggedIn()) { PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); try { startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST); } catch (Exception e) { Log.d(DEBUG, e.toString()); } } else { startGoogleSignInActivity(RC_SIGN_IN_NEW_PRIVY_REQUEST); snackMsg(getString(R.string.request_location_permission)); } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == Constants.REQUEST_CODE_PLACE_PICKER) { if (resultCode == Activity.RESULT_OK) { Place place = PlacePicker.getPlace(data, getActivity()); if (place == null) { return; } // The place picker presents two selection options: "select this location" and // "nearby places". Only the nearby places selection returns a placeId we can // submit to the service; the location selection will return a hex-like 0xbeef // identifier for that position instead, which isn't what we want. Here we check // if the entire string is hex and clear the placeId if it is. String id = place.getId(); if (id.startsWith("0x") && id.matches("0x[0-9a-f]+")) { placeId.setText(""); beaconInstance.placeId = ""; } else { placeId.setText(id); beaconInstance.placeId = id; } LatLng placeLatLng = place.getLatLng(); latLng.setText(placeLatLng.toString()); beaconInstance.latitude = placeLatLng.latitude; beaconInstance.longitude = placeLatLng.longitude; updateBeacon(); } else { logErrorAndToast("Error loading place picker. Is the Places API enabled? " + "See https://developers.google.com/places/android-api/signup for more detail"); } } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_PICKER_REQUEST) { if (mProgressDialog != null) { mProgressDialog.dismiss(); } if (resultCode == Activity.RESULT_OK) { Place place = PlacePicker.getPlace(mContext, data); if (place != null) { String title = place.getName().toString(); LatLng latLng = place.getLatLng(); LocationPoint locationPoint = new LocationPoint(latLng.latitude, latLng.longitude, 0); if (mRemindItem.getWaypoint() == null) { mRemindItem.setWaypoint(new Waypoint("default", title, locationPoint)); } else { mRemindItem.getWaypoint().setTitle(title); mRemindItem.getWaypoint().setLocation(locationPoint); } setLocationAndDistanceText(); } } } else { super.onActivityResult(requestCode, resultCode, data); } }