Java 类com.google.android.gms.location.places.Places 实例源码

项目:Shush    文件:MainActivity.java   
public void refreshPlacesData(){
    Uri uri = PlacesContract.PlaceEntry.CONTENT_URI;
    Cursor dataCursor = getContentResolver().query(uri,
            null,
            null,
            null,null,null);
    if (dataCursor==null||dataCursor.getCount()==0) return;
    List<String> placeIds = new ArrayList<String>();
    while (dataCursor.moveToNext()){
        placeIds.add(dataCursor.getString(dataCursor.getColumnIndex(PlacesContract.PlaceEntry.COLUMN_PLACE_ID)));
    }
    PendingResult<PlaceBuffer> placeBufferPendingResult = Places.GeoDataApi.getPlaceById(mClient,
            placeIds.toArray(new String[placeIds.size()]));
    placeBufferPendingResult.setResultCallback(new ResultCallback<PlaceBuffer>() {
        @Override
        public void onResult(@NonNull PlaceBuffer places) {
            mAdapter.swapPlaces(places);
            mGeofencing.updateGeofencesList(places);
            if (mIsEnabled) mGeofencing.registerAllGeofences();
        }
    });
}
项目:MADBike    文件:PlaceAutocompleteAdapter.java   
private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) {
    if (mGoogleApiClient.isConnected()) {

        PendingResult<AutocompletePredictionBuffer> results =
                Places.GeoDataApi
                        .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                mBounds, mPlaceFilter);

        AutocompletePredictionBuffer autocompletePredictions = results
                .await(60, TimeUnit.SECONDS);

        final Status status = autocompletePredictions.getStatus();
        if (!status.isSuccess()) {
            Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
                    Toast.LENGTH_SHORT).show();
            autocompletePredictions.release();
            return null;
        }
        return DataBufferUtils.freezeAndClose(autocompletePredictions);
    }
    return null;
}
项目:MADBike    文件:SearchActivity.java   
private void initThings() {
    loadingManager = new LoadingManager(this);
    searchPresenter = new SearchPresenter(this);
    notificationManager = new NotificationManager(this);
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, 0 /* clientId */, this)
            .addApi(Places.GEO_DATA_API)
            .build();

    autoCompleteTextView.setOnItemClickListener(this);
    autoCompleteTextView.addTextChangedListener(this);
    autoCompleteTextView.setOnEditorActionListener(this);

    createPermissionListener();
    Dexter.checkPermission(locationPermissionListener, Manifest.permission.ACCESS_COARSE_LOCATION);

}
项目:Pickr    文件:DataManager.java   
public Observable<PlacePrediction> getAutocompleteResults(final GoogleApiClient mGoogleApiClient, final String query, final LatLngBounds bounds) {
    return Observable.create(new Observable.OnSubscribe<PlacePrediction>() {
        @Override
        public void call(Subscriber<? super PlacePrediction> subscriber) {

            PendingResult<AutocompletePredictionBuffer> results =
                    Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, query,
                            bounds, null);

            AutocompletePredictionBuffer autocompletePredictions = results
                    .await(60, TimeUnit.SECONDS);

            final Status status = autocompletePredictions.getStatus();
            if (!status.isSuccess()) {
                autocompletePredictions.release();
                subscriber.onError(null);
            } else {
                for (AutocompletePrediction autocompletePrediction : autocompletePredictions) {
                    subscriber.onNext(
                            new PlacePrediction(
                                    autocompletePrediction.getPlaceId(),
                                    autocompletePrediction.getDescription()
                            ));
                }
                autocompletePredictions.release();
                subscriber.onCompleted();
            }
        }
    });
}
项目:Pickr    文件:DataManager.java   
public Observable<PointOfInterest> getCompleteResult(final GoogleApiClient mGoogleApiClient, final String id) {
    return Observable.create(new Observable.OnSubscribe<PointOfInterest>() {
        @Override
        public void call(final Subscriber<? super PointOfInterest> subscriber) {
            final PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
                    .getPlaceById(mGoogleApiClient, id);
            placeResult.setResultCallback(new ResultCallback<PlaceBuffer>() {
                @Override
                public void onResult(PlaceBuffer places) {
                    if (!places.getStatus().isSuccess()) {
                        places.release();
                        subscriber.onError(null);
                    } else {
                        subscriber.onNext(PointOfInterest.fromPlace(places.get(0)));
                        places.close();
                        subscriber.onCompleted();
                    }
                }
            });
        }
    });
}
项目:Pickr    文件:SearchActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    ButterKnife.bind(this);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, 0, this)
            .addApi(Places.GEO_DATA_API)
            .build();

    mDataManager = PickrApplication.get(this).getComponent().dataManager();
    mSubscriptions = new CompositeSubscription();
    mLocationProvider = new ReactiveLocationProvider(this);
    mProgressDialog = DialogFactory.createProgressDialog(this, R.string.dialog_text_getting_location);

    setupToolbar();
    setupRecyclerView();
    retrieveDeviceCurrentLocation();
}
项目:AutocompleteLocation    文件:AutoCompleteAdapter.java   
private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) {
  if (mGoogleApiClient.isConnected()) {
    PendingResult<AutocompletePredictionBuffer> results =
        Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
            mBounds, mPlaceFilter);

    AutocompletePredictionBuffer autocompletePredictions = results.await(60, TimeUnit.SECONDS);

    final Status status = autocompletePredictions.getStatus();
    if (!status.isSuccess()) {
      Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
          Toast.LENGTH_SHORT).show();
      autocompletePredictions.release();
      return null;
    }

    return DataBufferUtils.freezeAndClose(autocompletePredictions);
  }
  return null;
}
项目:Addy-Android    文件:PlacesAPIActivity.java   
private void callPlaceDetectionApi() throws SecurityException {
    PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
            .getCurrentPlace(mGoogleApiClient, null);
    result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
        @Override
        public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
            for (PlaceLikelihood placeLikelihood : likelyPlaces) {
                Log.i(LOG_TAG, String.format("Place '%s' with " +
                                "likelihood: %g",
                        placeLikelihood.getPlace().getName(),
                        placeLikelihood.getLikelihood()));
            }
            likelyPlaces.release();
        }
    });
}
项目:go-jay    文件:PlaceAutoCompleteHelper.java   
public PlaceAutoCompleteHelper(AutoCompleteTextView ... act, FragmentActivity fa) {
    Context ctx = act[0].getContext();
    mGoogleApiClient = new GoogleApiClient.Builder(ctx)
        .enableAutoManage(fa, 0, this)
        .addApi(Places.GEO_DATA_API)
        .addApi(LocationServices.API)
        .build();
       mAdapter = new PlaceAutoCompleteAdapter(ctx, mGoogleApiClient,
                                            null);
    for (AutoCompleteTextView ac:act) {
        ac.setOnItemClickListener(mAutocompleteClickListener);
        ac.setAdapter(mAdapter);
        ac.setOnFocusChangeListener(this);
    }
    placeIcon = act[0].getContext().getResources().getDrawable(R.drawable.ic_map_marker);
}
项目:go-jay    文件:PlaceAutoCompleteHelper.java   
public PlaceAutoCompleteHelper(AutoCompleteTextView... act) {
    Context ctx = act[0].getContext();
    mGoogleApiClient = new GoogleApiClient.Builder(ctx)
        .addApi(Places.GEO_DATA_API)
        .addApi(LocationServices.API)
        .build();
       mAdapter = new PlaceAutoCompleteAdapter(ctx, mGoogleApiClient,
                                            null);
       for (AutoCompleteTextView ac:act) {
        ac.setOnItemClickListener(mAutocompleteClickListener);
        ac.setAdapter(mAdapter);
        ac.setOnFocusChangeListener(this);
    }

    //((Activity)ctx).getApplication().registerActivityLifecycleCallbacks(this);
}
项目:go-jay    文件:PlaceAutoCompleteHelper.java   
private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) {
    if (mGoogleApiClient.isConnected()) {
        PendingResult<AutocompletePredictionBuffer> results =
                  Places.GeoDataApi
            .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                        mBounds, mPlaceFilter);
                AutocompletePredictionBuffer autocompletePredictions = results
                  .await(60, TimeUnit.SECONDS);
                final Status status = autocompletePredictions.getStatus();
        if (!status.isSuccess()) {
            if (callback != null) callback.onSuggestFail(status);
            autocompletePredictions.release();
            return null;
        }
            return DataBufferUtils.freezeAndClose(autocompletePredictions);
    }
        return null;
}
项目:Stalker    文件:PlaceFragment.java   
void getCurrentPlace() throws SecurityException {
    PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi.getCurrentPlace(placeApiClient, null);
    result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
        @Override
        public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
            for (int i = 0; i < likelyPlaces.getCount() && i < 5; i++) {
                PlaceEntry place = new PlaceEntry();
                if (likelyPlaces.get(i).getLikelihood() == 0) continue;

                place.setName(likelyPlaces.get(i).getPlace().getName().toString());
                place.setLatLon(likelyPlaces.get(i).getPlace().getLatLng());
                myDataset.add(place);
                mAdapter.notifyItemInserted(myDataset.size() - 1);
            }
            getMapA();
            likelyPlaces.release();
        }
    });
}
项目:AddyHINT17    文件:PlacesAPIActivity.java   
private void callPlaceDetectionApi() throws SecurityException {
    PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
            .getCurrentPlace(mGoogleApiClient, null);
    result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
        @Override
        public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
            for (PlaceLikelihood placeLikelihood : likelyPlaces) {
                Log.i(LOG_TAG, String.format("Place '%s' with " +
                                "likelihood: %g",
                        placeLikelihood.getPlace().getName(),
                        placeLikelihood.getLikelihood()));
            }
            likelyPlaces.release();
        }
    });
}
项目:Gps    文件:Gps4Activity.java   
private void callPlaceDetectionApi() throws SecurityException {
    PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
            .getCurrentPlace(mGoogleApiClient, null);
    result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
        @Override
        public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
            for (PlaceLikelihood placeLikelihood : likelyPlaces) {
                Log.i(LOG_TAG, String.format("Place '%s' with " +
                                "likelihood: %g",
                        placeLikelihood.getPlace().getName(),
                        placeLikelihood.getLikelihood()));
                display.setText(placeLikelihood.getPlace().getAddress().toString());
                messageSending(placeLikelihood.getPlace().getAddress().toString());
                break;
            }
            likelyPlaces.release();
        }
    });
}
项目:Gps    文件:Gps4Activity.java   
private void callPlaceDetectionApi2(final String ph_number) throws SecurityException {
    PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
            .getCurrentPlace(mGoogleApiClient, null);
    result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
        @Override
        public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
            for (PlaceLikelihood placeLikelihood : likelyPlaces) {
                Log.i(LOG_TAG, String.format("Place '%s' with " +
                                "likelihood: %g",
                        placeLikelihood.getPlace().getName(),
                        placeLikelihood.getLikelihood()));
                display.setText(placeLikelihood.getPlace().getAddress().toString());
                messageSending_individual(ph_number,placeLikelihood.getPlace().getAddress().toString());
                break;
            }
            likelyPlaces.release();
        }
    });
}
项目:Crimson    文件:SearchClinics.java   
private void getLocation() {

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .addApi(Places.GEO_DATA_API)
                .addApi(Places.PLACE_DETECTION_API)
                .enableAutoManage(this, this)
                .build();

        mLocationRequest = LocationRequest.create()
                .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                .setInterval(10 * 1000)
                .setFastestInterval(1 * 1000);

    }
项目:mobile-app-dev-book    文件:MainActivity.java   
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        setSupportActionBar(toolbar);
        mAuth = FirebaseAuth.getInstance();
        GoogleApiClient apiClient;

        apiClient = new GoogleApiClient.Builder(this)
                .addApi(Places.GEO_DATA_API)
                .addApi(Places.PLACE_DETECTION_API)
                .enableAutoManage(this, this)
                .build();
        JournalPageAdapter pageAdapter = new JournalPageAdapter(getSupportFragmentManager());
        viewPager.setAdapter(pageAdapter);
//        tabLayout.setupWithViewPager(viewPager);
        viewPager.addOnPageChangeListener(pageListener);
        bottomTabs.setOnNavigationItemSelectedListener(bottomTabsSelected);
    }
项目:mobile-app-dev-book    文件:MainActivity.java   
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        setSupportActionBar(toolbar);
        mAuth = FirebaseAuth.getInstance();
        GoogleApiClient apiClient;

        apiClient = new GoogleApiClient.Builder(this)
                .addApi(Places.GEO_DATA_API)
                .addApi(Places.PLACE_DETECTION_API)
                .enableAutoManage(this, this)
                .build();
        JournalPageAdapter pageAdapter = new JournalPageAdapter(getSupportFragmentManager());
        viewPager.setAdapter(pageAdapter);
//        tabLayout.setupWithViewPager(viewPager);
        viewPager.addOnPageChangeListener(pageListener);
        bottomTabs.setOnNavigationItemSelectedListener(bottomTabsSelected);
    }
项目:Nibo    文件:LocationRepository.java   
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());
                            }
                            places.release();
                        }
                    });
        }
    }.subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread());
}
项目:Nibo    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mGoogleApiClient = new GoogleApiClient
            .Builder(this)
            .enableAutoManage(this, 0, this)
            .addApi(Places.GEO_DATA_API)
            .addApi(Places.PLACE_DETECTION_API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    initView();

}
项目:FireHelper    文件:MapsActivityCurrentPlace.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Retrieve location and camera position from saved instance state.
    if (savedInstanceState != null) {
        mLastKnownLocation = savedInstanceState.getParcelable(KEY_LOCATION);
        mCameraPosition = savedInstanceState.getParcelable(KEY_CAMERA_POSITION);
    }

    // Retrieve the content view that renders the map.
    setContentView(R.layout.activity_maps);

    // Build the Play services client for use by the Fused Location Provider and the Places API.
    // Use the addApi() method to request the Google Places API and the Fused Location Provider.
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this ,
                    this )
            .addConnectionCallbacks(this)
            .addApi(LocationServices.API)
            .addApi(Places.GEO_DATA_API)
            .addApi(Places.PLACE_DETECTION_API)
            .build();
    mGoogleApiClient.connect();

}
项目:BonAppetit_Android-Project    文件:MapsActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    //preparing GoogleApiClient
    mGoogleApiClient=new GoogleApiClient.Builder(this)
            .addApi(Places.GEO_DATA_API)
            .build();
    mGoogleApiClient.connect();
    //Yes! finally Firebase :P
    Firebase.setAndroidContext(this);
    mFirebase=new Firebase(FIREBASE_URL);
    mFirebase.child(FIREBASE_ROOT_NODE).addChildEventListener(this);

}
项目:BonAppetit_Android-Project    文件:MapsActivity.java   
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
    final String placeId=dataSnapshot.getKey();
    if(placeId!=null)
    {
        Places.GeoDataApi
                .getPlaceById(mGoogleApiClient,placeId)
                .setResultCallback(new ResultCallback<PlaceBuffer>() {
                    @Override
                    public void onResult(@NonNull PlaceBuffer places) {
                        LatLng location=places.get(0).getLatLng();
                        //CharSequence userName=places.get(1).getName();

                        //Toast.makeText(getApplicationContext(),"reached onChildAdded",Toast.LENGTH_SHORT).show();
                        addPointToView(location);
                        mMap.addMarker(new MarkerOptions()
                                .position(location));
                        //Toast.makeText(getApplicationContext(),"place added",Toast.LENGTH_SHORT).show();
                        places.release();
                    }
                });
    }

}
项目:AutocompleteLocation    文件:AutoCompleteAdapter.java   
private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) {
  if (mGoogleApiClient.isConnected()) {
    PendingResult<AutocompletePredictionBuffer> results =
        Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
            mBounds, mPlaceFilter);

    AutocompletePredictionBuffer autocompletePredictions = results.await(60, TimeUnit.SECONDS);

    final Status status = autocompletePredictions.getStatus();
    if (!status.isSuccess()) {
      Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
          Toast.LENGTH_SHORT).show();
      autocompletePredictions.release();
      return null;
    }

    return DataBufferUtils.freezeAndClose(autocompletePredictions);
  }
  return null;
}
项目:Dryver    文件:ActivityDryverMap.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_request_map);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    //Instantiate GoogleApiClient, using GEO DATA and PLACE DETECTION API
    mClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .addApi(Places.GEO_DATA_API)
            .addApi(Places.PLACE_DETECTION_API)
            .build();
}
项目:Dryver    文件:ActivityRequestMap.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_request_map);

    mRoute = new ArrayList<>();
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    //Instantiate GoogleApiClient, using GEO DATA and PLACE DETECTION API
    mClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .addApi(Places.GEO_DATA_API)
            .addApi(Places.PLACE_DETECTION_API)
            .build();
}
项目:Stalker    文件:PlaceFragment.java   
void getCurrentPlace() throws SecurityException {
    PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi.getCurrentPlace(placeApiClient, null);
    result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
        @Override
        public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
            for (int i = 0; i < likelyPlaces.getCount() && i < 5; i++) {
                PlaceEntry place = new PlaceEntry();
                if (likelyPlaces.get(i).getLikelihood() == 0) continue;

                place.setName(likelyPlaces.get(i).getPlace().getName().toString());
                place.setLatLon(likelyPlaces.get(i).getPlace().getLatLng());
                myDataset.add(place);
                mAdapter.notifyItemInserted(myDataset.size() - 1);
            }
            getMapA();
            likelyPlaces.release();
        }
    });
}
项目:PlacesAPI    文件:PlacesAPIActivity.java   
private void callPlaceDetectionApi() throws SecurityException {
    PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
            .getCurrentPlace(mGoogleApiClient, null);
    result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
        @Override
        public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
            for (PlaceLikelihood placeLikelihood : likelyPlaces) {
                Log.i(LOG_TAG, String.format("Place '%s' with " +
                                "likelihood: %g",
                        placeLikelihood.getPlace().getName(),
                        placeLikelihood.getLikelihood()));
            }
            likelyPlaces.release();
        }
    });
}
项目:Akwukwo    文件:SearchLocationActivity.java   
@Override
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
    /*
     Retrieve the place ID of the selected item from the Adapter.
     The adapter stores each Place suggestion in a AutocompletePrediction from which we
     read the place ID and title.
      */
    final AutocompletePrediction item = mAdapter.getItem (position);
    final String placeId = item.getPlaceId ();
    final CharSequence primaryText = item.getPrimaryText (null);
    Log.i("", "Autocomplete item selected: " + primaryText);

    /*
     Issue a request to the Places Geo Data API to retrieve a Place object with additional
     details about the place.
      */
    PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
            .getPlaceById (mGoogleApiClient, placeId);
    placeResult.setResultCallback (mUpdatePlaceDetailsCallback);

    Log.i("", "Called getPlaceById to get Place details for " + placeId);
    mSearchLocation.setThreshold(1000);
}
项目:PlaceAPIAutocomplete    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mGoogleApiClient = new GoogleApiClient.Builder(MainActivity.this)
            .addApi(Places.GEO_DATA_API)
            .enableAutoManage(this, GOOGLE_API_CLIENT_ID, this)
            .addConnectionCallbacks(this)
            .build();
    mAutocompleteTextView = (AutoCompleteTextView) findViewById(R.id
            .autoCompleteTextView);
    mAutocompleteTextView.setThreshold(3);
    mNameTextView = (TextView) findViewById(R.id.name);
    mAddressTextView = (TextView) findViewById(R.id.address);
    mIdTextView = (TextView) findViewById(R.id.place_id);
    mPhoneTextView = (TextView) findViewById(R.id.phone);
    mWebTextView = (TextView) findViewById(R.id.web);
    mAttTextView = (TextView) findViewById(R.id.att);
    mAutocompleteTextView.setOnItemClickListener(mAutocompleteClickListener);
    mPlaceArrayAdapter = new PlaceArrayAdapter(this, android.R.layout.simple_list_item_1,
            BOUNDS_MOUNTAIN_VIEW, null);
    mAutocompleteTextView.setAdapter(mPlaceArrayAdapter);
}
项目:gaso    文件:MapGasoFragment.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
    }
    markers = new WeakHashMap<>();
    mGoogleApiClient = new GoogleApiClient
            .Builder(getContext())
            .addApi(Places.GEO_DATA_API)
            .addApi(Places.PLACE_DETECTION_API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    FragmentManager fm = getChildFragmentManager();
    if (supportMapFragment == null) {
        supportMapFragment = SupportMapFragment.newInstance();
        supportMapFragment.getMapAsync(this);
        fm.beginTransaction().replace(R.id.map, supportMapFragment).commit();
    }
    locationHelper = LocationHelper.getINSTANCE(getActivity());
}
项目:ExamplesAndroid    文件:MainActivity.java   
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    /*
     Retrieve the place ID of the selected item from the Adapter.
     The adapter stores each Place suggestion in a AutocompletePrediction from which we
     read the place ID and title.
      */
    final AutocompletePrediction item = mAdapter.getItem(position);
    final String placeId = item.getPlaceId();
    final CharSequence primaryText = item.getPrimaryText(null);

    Log.i(TAG, "Autocomplete item selected: " + primaryText);

    /*
     Issue a request to the Places Geo Data API to retrieve a Place object with additional
     details about the place.
      */
    PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
            .getPlaceById(mGoogleApiClient, placeId);
    placeResult.setResultCallback(mUpdatePlaceDetailsCallback);

    Toast.makeText(getApplicationContext(), "Clicked: " + primaryText,
            Toast.LENGTH_SHORT).show();
    Log.i(TAG, "Called getPlaceById to get Place details for " + placeId);
}
项目:amos-ss15-proj2    文件:JoinSearchFragment.java   
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    setHasOptionsMenu(true);


    if (googleApiClient == null) {
        googleApiClient = new GoogleApiClient.Builder(getActivity().getApplicationContext())
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Places.GEO_DATA_API)
                .build();

        googleApiClient.connect();
    } else if (!googleApiClient.isConnected()) {
        googleApiClient.connect();
    }

    View view = inflater.inflate(R.layout.fragment_join_search, container, false);
    return view;
}
项目:amos-ss15-proj2    文件:OfferTripFragment.java   
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    if (googleApiClient == null) {
        googleApiClient = new GoogleApiClient.Builder(getActivity().getApplicationContext())
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Places.GEO_DATA_API)
                .build();

        googleApiClient.connect();
    } else if (!googleApiClient.isConnected()) {
        googleApiClient.connect();
    }


    return inflater.inflate(R.layout.fragment_offer_trip, container, false);
}
项目:io2015-codelabs    文件:MapsActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    // Set up Google Maps
    SupportMapFragment mapFragment = (SupportMapFragment)
            getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    // Set up the API client for Places API
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Places.GEO_DATA_API)
            .build();
    mGoogleApiClient.connect();

    // Set up Firebase
    Firebase.setAndroidContext(this);
    mFirebase = new Firebase(FIREBASE_URL);
    mFirebase.child(FIREBASE_ROOT_NODE).addChildEventListener(this);
}
项目:io2015-codelabs    文件:MapsActivity.java   
/**
 * Act upon new check-outs when they appear.
 */
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
    String placeId = dataSnapshot.getKey();
    if (placeId != null) {
        Places.GeoDataApi
                .getPlaceById(mGoogleApiClient, placeId)
                .setResultCallback(new ResultCallback<PlaceBuffer>() {
                           @Override
                           public void onResult(PlaceBuffer places) {
                               LatLng location = places.get(0).getLatLng();
                               addPointToViewPort(location);
                               mMap.addMarker(new MarkerOptions().position(location));
                               places.release();
                           }
                       }
                );
    }
}
项目:AndroidDemoProjects    文件:MainActivity.java   
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();
       }
   } );
}
项目:AndroidDemoProjects    文件:MainActivity.java   
private void guessCurrentPlace() {
    PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi.getCurrentPlace( mGoogleApiClient, null );
    result.setResultCallback( new ResultCallback<PlaceLikelihoodBuffer>() {
        @Override
        public void onResult( PlaceLikelihoodBuffer likelyPlaces ) {

            PlaceLikelihood placeLikelihood = likelyPlaces.get( 0 );
            String content = "";
            if( placeLikelihood != null && placeLikelihood.getPlace() != null && !TextUtils.isEmpty( placeLikelihood.getPlace().getName() ) )
                content = "Most likely place: " + placeLikelihood.getPlace().getName() + "\n";
            if( placeLikelihood != null )
                content += "Percent change of being there: " + (int) ( placeLikelihood.getLikelihood() * 100 ) + "%";
            mTextView.setText( content );

            likelyPlaces.release();
        }
    });
}
项目:voyager2-android    文件:GoogleApiClientActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(LocationServices.API)
            .addApi(Places.GEO_DATA_API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    LatLng center;
    Location lastKnownLocation = ConnectionUtils.getLastKnownLocation(this);
    if (lastKnownLocation == null) {
        // Assume center of Toronto for bounds calculation to start with until a location is detected
        center = new LatLng(43.7001100, -79.4163000);
    } else {
        center = new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude());
    }
    setPlaceAutoCompleteAdapterBounds(center);
}
项目:GitHub    文件:ReactiveLocationProvider.java   
/**
 * Returns observable that fetches current place from Places API. To flatmap and auto release
 * buffer to {@link com.google.android.gms.location.places.PlaceLikelihood} observable use
 * {@link DataBufferObservable}.
 *
 * @param placeFilter filter
 * @return observable that emits current places buffer and completes
 */
public Observable<PlaceLikelihoodBuffer> getCurrentPlace(@Nullable final PlaceFilter placeFilter) {
    return getGoogleApiClientObservable(Places.PLACE_DETECTION_API, Places.GEO_DATA_API)
            .flatMap(new Func1<GoogleApiClient, Observable<PlaceLikelihoodBuffer>>() {
                @Override
                public Observable<PlaceLikelihoodBuffer> call(GoogleApiClient api) {
                    return fromPendingResult(Places.PlaceDetectionApi.getCurrentPlace(api, placeFilter));
                }
            });
}