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

项目:2017NASA_NCTUBeach    文件:LocationSelectActivity.java   
@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();
    }

}
项目:Shush    文件:MainActivity.java   
/***
 * 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();
    }
}
项目:ElephantAsia    文件:AddProfilFragment.java   
/**
 * 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());
}
项目:ElephantAsia    文件:AddProfilFragment.java   
/**
 * 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());
}
项目:ElephantAsia    文件:AddRegistrationFragment.java   
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());
  }
项目:ElephantAsia    文件:EditRegistrationFragment.java   
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());
  }
项目:ElephantAsia    文件:EditProfilFragment.java   
/**
 * 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());
}
项目:ElephantAsia    文件:EditProfilFragment.java   
/**
 * 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());
}
项目:travelers-diary    文件:ReminderItemFragment.java   
@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);
}
项目:LivePokemonFinder    文件:MainActivity.java   
@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);

        }
    }
}
项目:react-native-google-place-picker    文件:RNGooglePlacePickerModule.java   
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;
    }
}
项目:PlacePicker    文件:PlacePickerActivity.java   
@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();
            }
        }
    });
}
项目:PlacePicker    文件:PlacePickerActivity.java   
@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);
    }
}
项目:ProjectFive    文件:BidsDisplayActivity.java   
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();
        }
    }
}
项目:gaso    文件:ExpensesRegisterActivity.java   
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();
            }
        }
    }
}
项目:libertacao-android    文件:EditEventActivity.java   
/**
 * 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();
    }
}
项目:compass-project    文件:CompassActivity.java   
@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);
    }
}
项目:techcomm-map-android    文件:AddEventActivity.java   
/**
 * 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);
    }
}
项目:travelers-diary    文件:ReminderItemFragment.java   
@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);
}
项目:amos-ss15-proj2    文件:JoinSearchFragment.java   
@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);
    }
}
项目:io2015-codelabs    文件:MapsActivity.java   
@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);
    }
}
项目:MarketAndroid    文件:MainNavigationActivity.java   
@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)));
        }
    }
}
项目:Pickr    文件:MainActivity.java   
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);
        }
    }
}
项目:Viajes    文件:AddActivity.java   
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);
    }


}
项目:PeSanKita-android    文件:AttachmentManager.java   
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);
  }
}
项目:GeoFencer    文件:SettingsActivity.java   
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();
    }
}
项目:GeoFencer    文件:SettingsActivity.java   
@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);
        }
    }
}
项目:Udacity_Sunshine    文件:LocationEditTextPreference.java   
@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;
}
项目:Sega    文件:ProfileDetailFragment.java   
private void locationPlacesIntent() {

        try {
            PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
            startActivityForResult(builder.build(getActivity()), PLACE_PICKER_REQUEST);
        } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }
    }
项目:Sega    文件:AddProductActivity.java   
private void locationPlacesIntent() {

        try {
            PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
            startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
        } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }
    }
项目:Sega    文件:ChatActivity.java   
@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);
            }
        }
    }


}
项目:Sega    文件:ChatActivity.java   
/**
 * 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();
    }
}
项目:ElephantAsia    文件:LocationDialog.java   
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());
  }
}
项目:twoh-places-location-api-sample    文件:MainActivity.java   
@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);
        }
    }
}
项目:MyGeofencer    文件:AddGeofenceActivity.java   
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();
        }
    }
}
项目:BonAppetit_Android-Project    文件:MapsActivity.java   
@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);
    }
}
项目:Advanced_Android_Development_Wear    文件:LocationEditTextPreference.java   
@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;
}
项目:Privy    文件:MainActivity.java   
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));
    }
}
项目:BeeksBeacon    文件:ManageBeaconFragment.java   
@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");
        }
    }
}
项目:travelers-diary    文件:ReminderItemFragment.java   
@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);
    }
}