com.google.android.gms.location.places.Place Java Examples

The following examples show how to use com.google.android.gms.location.places.Place. 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: MainActivity.java    From protrip with MIT License 6 votes vote down vote up
@Override
public void onPlaceSelected(Place place) {
    Log.i(TAG, "Place Selected: " + place.getName());
    final String cityId = String.valueOf(place.getId());
    final String cityName = String.valueOf(place.getName());
    final String cityLat = String.valueOf(place.getLatLng().latitude);
    final String cityLng = String.valueOf(place.getLatLng().longitude);

    Intent intent = new Intent(this, CityActivity.class);
    intent.putExtra("cityId", cityId);
    intent.putExtra("cityName", cityName);
    intent.putExtra("cityLat", cityLat);
    intent.putExtra("cityLng", cityLng);
    startActivity(intent);

}
 
Example #2
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
private void displayPlace( Place place ) {
    if( place == null )
        return;

    String content = "";
    if( !TextUtils.isEmpty( place.getName() ) ) {
        content += "Name: " + place.getName() + "\n";
    }
    if( !TextUtils.isEmpty( place.getAddress() ) ) {
        content += "Address: " + place.getAddress() + "\n";
    }
    if( !TextUtils.isEmpty( place.getPhoneNumber() ) ) {
        content += "Phone: " + place.getPhoneNumber();
    }

    mTextView.setText( content );
}
 
Example #3
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
private void findPlaceById( String id ) {
    if( TextUtils.isEmpty( id ) || mGoogleApiClient == null || !mGoogleApiClient.isConnected() )
        return;

   Places.GeoDataApi.getPlaceById( mGoogleApiClient, id ) .setResultCallback( new ResultCallback<PlaceBuffer>() {
       @Override
       public void onResult(PlaceBuffer places) {
           if( places.getStatus().isSuccess() ) {
               Place place = places.get( 0 );
               displayPlace( place );
               mPredictTextView.setText( "" );
               mAdapter.clear();
           }

           //Release the PlaceBuffer to prevent a memory leak
           places.release();
       }
   } );
}
 
Example #4
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
private void detectNearbyPlaces() {
    if( !checkLocationPermission() ) {
        return;
    }

    Awareness.SnapshotApi.getPlaces(mGoogleApiClient)
            .setResultCallback(new ResultCallback<PlacesResult>() {
                @Override
                public void onResult(@NonNull PlacesResult placesResult) {
                    Place place;
                    for( PlaceLikelihood placeLikelihood : placesResult.getPlaceLikelihoods() ) {
                        place = placeLikelihood.getPlace();
                        Log.e("Tuts+", place.getName().toString() + "\n" + place.getAddress().toString() );
                        Log.e("Tuts+", "Rating: " + place.getRating() );
                        Log.e("Tuts+", "Likelihood that the user is here: " + placeLikelihood.getLikelihood() * 100 + "%");
                    }
                }
            });
}
 
Example #5
Source File: SuggestionsProvider.java    From Nibo with MIT License 6 votes vote down vote up
public Observable<Place> getPlaceByID(final String placeId) {
    return new Observable<Place>() {
        @Override
        protected void subscribeActual(final Observer<? super Place> observer) {
            Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId)
                    .setResultCallback(new ResultCallback<PlaceBuffer>() {
                        @Override
                        public void onResult(@NonNull PlaceBuffer places) {
                            if (places.getStatus().isSuccess()) {
                                final Place thatPlace = places.get(0);
                                LatLng queriedLocation = thatPlace.getLatLng();
                                Log.v("Latitude is", "" + queriedLocation.latitude);
                                Log.v("Longitude is", "" + queriedLocation.longitude);

                                observer.onNext(thatPlace.freeze());
                            } else {

                            }
                            places.release();
                        }
                    });
        }
    }.subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread());
}
 
Example #6
Source File: MapsActivity.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: MainActivity.java    From android-play-places with Apache License 2.0 6 votes vote down vote up
/**
 * Callback invoked when a place has been selected from the PlaceAutocompleteFragment.
 */
@Override
public void onPlaceSelected(Place place) {
    Log.i(TAG, "Place Selected: " + place.getName());

    // Format the returned place's details and display them in the TextView.
    mPlaceDetailsText.setText(formatPlaceDetails(getResources(), place.getName(), place.getId(),
            place.getAddress(), place.getPhoneNumber(), place.getWebsiteUri()));

    CharSequence attributions = place.getAttributions();
    if (!TextUtils.isEmpty(attributions)) {
        mPlaceAttribution.setText(Html.fromHtml(attributions.toString()));
    } else {
        mPlaceAttribution.setText("");
    }
}
 
Example #8
Source File: SelfRouteDetailActivity.java    From kute with Apache License 2.0 6 votes vote down vote up
private void configurePlace(int requestCode,int resultCode,Intent data){
    if (resultCode == RESULT_OK) {
        Place place = PlaceAutocomplete.getPlace(this, data);
        if(requestCode==PLACE_AUTOCOMPLETE_REQUEST_CODE_SOURCE) {
            source_address=place.getAddress().toString();
            from.setText(place.getAddress());
            source_cords=Double.toString(place.getLatLng().latitude)+","+Double.toString(place.getLatLng().longitude);
            source_name_string=place.getName().toString();
        }
        else if(requestCode==PLACE_AUTOCOMPLETE_REQUEST_CODE_DESTINATION) {
            destination_address=place.getAddress().toString();
            to.setText(place.getAddress());
            destination_cords=Double.toString(place.getLatLng().latitude)+","+Double.toString(place.getLatLng().longitude);
            destination_name_string=place.getName().toString();
        }
        Log.i(TAG, "Place: " + place.getAddress());
    } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
        Status status = PlaceAutocomplete.getStatus(this, data);
        // TODO: Handle the error.
        Log.i(TAG, status.getStatusMessage());

    } else if (resultCode == RESULT_CANCELED) {
        // The user canceled the operation.
    }

}
 
Example #9
Source File: OriginDestinationPickerPresenter.java    From Nibo with MIT License 6 votes vote down vote up
@Override
public void onGetPlaceDetailsSuccess(Place place) {
    getView().hideLoading();
    getView().closeSuggestions();
    NiboSearchSuggestionItem searchSuggestionItem = (NiboSearchSuggestionItem) getPlaceDetailsParams
            .getData(NiboConstants.SUGGESTION_ITEM_PARAM, null);
    if (getView().isOriginIndicatorViewChecked()) {
        mSelectedOriginDestination.setOriginItem(searchSuggestionItem);
        mSelectedOriginDestination.setOriginLatLng(place.getLatLng());
        getView().setPlaceDataOrigin(place, searchSuggestionItem);
    } else if (getView().isDestinationIndicatorViewChecked()) {
        mSelectedOriginDestination.setDestinationItem(searchSuggestionItem);
        mSelectedOriginDestination.setDestinationLatLng(place.getLatLng());
        getView().setPlaceDataDestination(place, searchSuggestionItem);
    }
}
 
Example #10
Source File: AddRouteActivity.java    From kute with Apache License 2.0 6 votes vote down vote up
private void configurePlace(int requestCode,int resultCode,Intent data){
    if (resultCode == RESULT_OK) {
        Place place = PlaceAutocomplete.getPlace(this, data);
        if(requestCode==PLACE_AUTOCOMPLETE_REQUEST_CODE_SOURCE) {
            source.setText(place.getAddress());
            source_cords=Double.toString(place.getLatLng().latitude)+","+Double.toString(place.getLatLng().longitude);
            source_name_string=place.getName().toString();
        }
        else if(requestCode==PLACE_AUTOCOMPLETE_REQUEST_CODE_DESTINATION) {
            destination.setText(place.getAddress());
            destination_cords=Double.toString(place.getLatLng().latitude)+","+Double.toString(place.getLatLng().longitude);
            destination_name_string=place.getName().toString();
        }
        Log.i(TAG, "Place: " + place.getAddress());
    } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
        Status status = PlaceAutocomplete.getStatus(this, data);
        // TODO: Handle the error.
        Log.i(TAG, status.getStatusMessage());

    } else if (resultCode == RESULT_CANCELED) {
        // The user canceled the operation.
    }

}
 
Example #11
Source File: AddTrip.java    From kute with Apache License 2.0 6 votes vote down vote up
private void configurePlace(int requestCode,int resultCode,Intent data){
    if (resultCode == RESULT_OK) {
        Place place = PlaceAutocomplete.getPlace(this, data);
        if(requestCode==PLACE_AUTOCOMPLETE_REQUEST_CODE_SOURCE) {
            source_string=place.getName().toString();
            source.setText(place.getAddress());
            source_cords=Double.toString(place.getLatLng().latitude)+","+Double.toString(place.getLatLng().longitude);
            source_address=place.getAddress().toString();
        }
        else if(requestCode==PLACE_AUTOCOMPLETE_REQUEST_CODE_DESTINATION) {
            destination_string=place.getAddress().toString();
            destination.setText(place.getAddress());
            dest_cords=Double.toString(place.getLatLng().latitude)+","+Double.toString(place.getLatLng().longitude);
            destination_address=place.getAddress().toString();
        }
        Log.i(TAG, "Place: " + place.getAddress());
    } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
        Status status = PlaceAutocomplete.getStatus(this, data);
        // TODO: Handle the error.
        Log.i(TAG, status.getStatusMessage());

    } else if (resultCode == RESULT_CANCELED) {
        // The user canceled the operation.
    }

}
 
Example #12
Source File: StartRide.java    From kute with Apache License 2.0 6 votes vote down vote up
private void configurePlace(int requestCode,int resultCode,Intent data){
    if (resultCode == RESULT_OK) {
        Place place = PlaceAutocomplete.getPlace(this, data);
        if(requestCode==PLACE_AUTOCOMPLETE_REQUEST_CODE_SOURCE) {
            source_string=place.getName().toString();
            source_text.setText(source_string);
            source_cords=Double.toString(place.getLatLng().latitude)+","+Double.toString(place.getLatLng().longitude);
            source_address=place.getAddress().toString();
        }
        else if(requestCode==PLACE_AUTOCOMPLETE_REQUEST_CODE_DESTINATION) {
            destination_string=place.getName().toString();
            destination_text.setText(destination_string);
            destination_cords=Double.toString(place.getLatLng().latitude)+","+Double.toString(place.getLatLng().longitude);
            destination_address=place.getAddress().toString();
        }
        Log.i(TAG, "Place: " + place.getAddress());
    } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
        Status status = PlaceAutocomplete.getStatus(this, data);
        // TODO: Handle the error.
        Log.i(TAG, status.getStatusMessage());

    } else if (resultCode == RESULT_CANCELED) {
        // The user canceled the operation.
    }

}
 
Example #13
Source File: MainActivity.java    From ExamplesAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(PlaceBuffer places) {
    if (!places.getStatus().isSuccess()) {
        // Request did not complete successfully
        Log.e(TAG, "Place query did not complete. Error: " + places.getStatus().toString());
        places.release();
        return;
    }
    // Get the Place object from the buffer.
    final Place place = places.get(0);

    // Format details of the place for display and show it in a TextView.
    mPlaceDetailsText.setText(formatPlaceDetails(getResources(), place.getName(),
            place.getId(), place.getAddress(), place.getPhoneNumber(),
            place.getWebsiteUri()));

    // Display the third party attributions if set.
    final CharSequence thirdPartyAttribution = places.getAttributions();
    if (thirdPartyAttribution == null) {
        mPlaceDetailsAttribution.setVisibility(View.GONE);
    } else {
        mPlaceDetailsAttribution.setVisibility(View.VISIBLE);
        mPlaceDetailsAttribution.setText(Html.fromHtml(thirdPartyAttribution.toString()));
    }

    Log.i(TAG, "Place details received: " + place.getName());

    places.release();
}
 
Example #14
Source File: ViewActivity.java    From memoir with Apache License 2.0 5 votes vote down vote up
@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 #15
Source File: SearchPlaceOnMapActivity.java    From Airbnb-Android-Google-Map-View with MIT License 5 votes vote down vote up
@Override
public void onResult(PlaceBuffer places) {
    if (!places.getStatus().isSuccess()) {
        places.release();
        return;
    }
    // Get the Place object from the buffer.
    final Place place = places.get(0);
    hideKeyboard();
    mLatitude=String.valueOf(place.getLatLng().latitude);
    mLongitude=String.valueOf(place.getLatLng().longitude);
    LatLng newLatLngTemp = new LatLng(place.getLatLng().latitude, place.getLatLng().longitude);
    // LatLng centerLatLng=new LatLng(mMap.getCameraPosition().target.latitude,mMap.getCameraPosition().target.longitude);
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(newLatLngTemp, 15f));
}
 
Example #16
Source File: MainActivity.java    From Locate-driver with GNU General Public License v3.0 5 votes vote down vote up
private void setPlace(Place place) {
    if (place == null) {
        this.place = null;
    } else {
        this.place = new LDPlace(place.getName() + "", place.getId(), place.getLatLng().latitude, place.getLatLng().longitude);
    }

    this.saveData();
}
 
Example #17
Source File: SearchActivity.java    From Car-Pooling with MIT License 5 votes vote down vote up
/**
 * 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 #18
Source File: ChatActivity.java    From NaviBee with GNU General Public License v3.0 5 votes vote down vote up
@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 #19
Source File: MainActivity.java    From android-play-places with Apache License 2.0 5 votes vote down vote up
@Override
public void onComplete(Task<PlaceBufferResponse> task) {
    try {
        PlaceBufferResponse places = task.getResult();

        // Get the Place object from the buffer.
        final Place place = places.get(0);

        // Format details of the place for display and show it in a TextView.
        mPlaceDetailsText.setText(formatPlaceDetails(getResources(), place.getName(),
                place.getId(), place.getAddress(), place.getPhoneNumber(),
                place.getWebsiteUri()));

        // Display the third party attributions if set.
        final CharSequence thirdPartyAttribution = places.getAttributions();
        if (thirdPartyAttribution == null) {
            mPlaceDetailsAttribution.setVisibility(View.GONE);
        } else {
            mPlaceDetailsAttribution.setVisibility(View.VISIBLE);
            mPlaceDetailsAttribution.setText(
                    Html.fromHtml(thirdPartyAttribution.toString()));
        }

        Log.i(TAG, "Place details received: " + place.getName());

        places.release();
    } catch (RuntimeRemoteException e) {
        // Request did not complete successfully
        Log.e(TAG, "Place query did not complete.", e);
        return;
    }
}
 
Example #20
Source File: MainActivity.java    From android-play-places with Apache License 2.0 5 votes vote down vote up
/**
 * Called after the autocomplete activity has finished to return its result.
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Check that the result was from the autocomplete widget.
    if (requestCode == REQUEST_CODE_AUTOCOMPLETE) {
        if (resultCode == RESULT_OK) {
            // Get the user's selected place from the Intent.
            Place place = PlaceAutocomplete.getPlace(this, data);
            Log.i(TAG, "Place Selected: " + place.getName());

            // Format the place's details and display them in the TextView.
            mPlaceDetailsText.setText(formatPlaceDetails(getResources(), place.getName(),
                    place.getId(), place.getAddress(), place.getPhoneNumber(),
                    place.getWebsiteUri()));

            // Display attributions if required.
            CharSequence attributions = place.getAttributions();
            if (!TextUtils.isEmpty(attributions)) {
                mPlaceAttribution.setText(Html.fromHtml(attributions.toString()));
            } else {
                mPlaceAttribution.setText("");
            }
        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status status = PlaceAutocomplete.getStatus(this, data);
            Log.e(TAG, "Error: Status = " + status.toString());
        } else if (resultCode == RESULT_CANCELED) {
            // Indicates that the activity closed before a selection was made. For example if
            // the user pressed the back button.
        }
    }
}
 
Example #21
Source File: AutoCompleteAdapter.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private void displayPredictiveResults( String query )
{
    //Southwest corner to Northeast corner.
    LatLngBounds bounds = new LatLngBounds( new LatLng( 39.906374, -105.122337 ), new LatLng( 39.949552, -105.068779 ) );

    //Filter: https://developers.google.com/places/supported_types#table3
    List<Integer> filterTypes = new ArrayList<Integer>();
    filterTypes.add( Place.TYPE_ESTABLISHMENT );

    Places.GeoDataApi.getAutocompletePredictions( mGoogleApiClient, query, bounds, AutocompleteFilter.create( filterTypes ) )
        .setResultCallback (
            new ResultCallback<AutocompletePredictionBuffer>() {
                @Override
                public void onResult( AutocompletePredictionBuffer buffer ) {

                    if( buffer == null )
                        return;

                    if( buffer.getStatus().isSuccess() ) {
                        for( AutocompletePrediction prediction : buffer ) {
                            //Add as a new item to avoid IllegalArgumentsException when buffer is released
                            add( new AutoCompletePlace( prediction.getPlaceId(), prediction.getDescription() ) );
                        }
                    }

                    //Prevent memory leak by releasing buffer
                    buffer.release();
                }
            }, 60, TimeUnit.SECONDS );
}
 
Example #22
Source File: PlaceSearchFragment.java    From Place-Search-Service with MIT License 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        Place place = PlaceAutocomplete.getPlace(context, data);
        Log.e("lingquan", "the task is " + resultCode + " " + requestCode + "     " + PlaceAutocomplete.getPlace(context, data).toString());
        oldLocation = place.getAddress().toString();
        mPlaceSearchLocation.setText(place.getAddress());
    }
}
 
Example #23
Source File: EventEditActivity.java    From NaviBee with GNU General Public License v3.0 5 votes vote down vote up
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 #24
Source File: EventEditActivity.java    From NaviBee with GNU General Public License v3.0 5 votes vote down vote up
private String getPlaceDisplayName(Place place) {
    String placeName = place.getName().toString();
    if (placeName.matches("\\d+°((\\d+'([\\d.]+\")?)?)?[NS] \\d+°((\\d+'([\\d.]+\")?)?)?[WE]")) {
        // if place name is a coordinate
        placeName = place.getAddress().toString();
    }
    return placeName;
}
 
Example #25
Source File: AutoCompleteLocation.java    From AutocompleteLocation with Apache License 2.0 5 votes vote down vote up
@Override public void onResult(@NonNull PlaceBuffer places) {
  if (!places.getStatus().isSuccess()) {
    places.release();
    return;
  }
  final Place place = places.get(0);
  if (mAutoCompleteLocationListener != null) {
    mAutoCompleteLocationListener.onItemSelected(place);
  }
  places.release();
}
 
Example #26
Source File: NiboPickerFragment.java    From Nibo with MIT License 4 votes vote down vote up
@Override
public void setPlaceData(Place place) {
    addSingleMarkerToMap(place.getLatLng());
}
 
Example #27
Source File: PlacePickerFragment.java    From android-play-places with Apache License 2.0 4 votes vote down vote up
/**
 * 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)
}
 
Example #28
Source File: NiboPickerPresenter.java    From Nibo with MIT License 4 votes vote down vote up
@Override
public void onNext(Place place) {
    super.onNext(place);
    onGetPlaceDetailsSuccess(place);
}
 
Example #29
Source File: NiboPickerPresenter.java    From Nibo with MIT License 4 votes vote down vote up
@Override
public void onGetPlaceDetailsSuccess(Place place) {
    getView().setPlaceData(place);
}
 
Example #30
Source File: SettingsFragment.java    From BackPackTrackII with GNU General Public License v3.0 4 votes vote down vote up
@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);
}