@Overridepublic boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_search: try { PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder(); Intent intent = intentBuilder.build(this); // Start the Intent by requesting a result, identified by a request code. startActivityForResult(intent, REQUEST_PLACE_PICKER); } catch (GooglePlayServicesRepairableException e) { GooglePlayServicesUtil.getErrorDialog(e.getConnectionStatusCode(), this, 0); } catch (GooglePlayServicesNotAvailableException e) { Toast.makeText(this, "Google Play Services is not available.",Toast.LENGTH_LONG).show(); } return true; default: return super.onOptionsItemSelected(item); }}
final Place place = PlacePicker.getPlace(data, this);
final CharSequence name = place.getName();final CharSequence address = place.getAddress();final CharSequence phone = place.getPhoneNumber();
mMap.addMarker(new MarkerOptions() .position(place.getLatLng()) .title(name.toString())
@Overridepublic 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) { /* 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, this); /* 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 map mMap.addMarker(new MarkerOptions() .position(place.getLatLng()) .title(name.toString()) ); // Print data to debug log Log.d(TAG, "Place selected: " + placeId + " (" + name.toString() + ")"); } } else { super.onActivityResult(requestCode, resultCode, data); } // END_INCLUDE(activity_result)}
Map mLocation = new HashMap();mLocation.put("timestamp", mLastUpdateTime);Map mCoordinate = new HashMap();mCoordinate.put(“latitude”, place.getLatLng().latitude);mCoordinate.put(“longitude”, place.getLatLng().longitude);mLocation.put("location", mCoordinate); mLocation.put("place_id", place.getId());myFirebaseRef.push().setValue(mLocation);
Give us feedback in our Product Forums.