本文整理汇总了Java中com.google.android.gms.location.places.ui.PlacePicker类的典型用法代码示例。如果您正苦于以下问题:Java PlacePicker类的具体用法?Java PlacePicker怎么用?Java PlacePicker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PlacePicker类属于com.google.android.gms.location.places.ui包,在下文中一共展示了PlacePicker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onActivityResult
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
@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();
}
}
示例2: onActivityResult
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
/***
* 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();
}
}
示例3: setCurrentLocation
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
/**
* 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());
}
示例4: setBirthLocation
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
/**
* 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());
}
示例5: setRegistrationLocation
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
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());
}
示例6: onWaypointTitleClick
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
@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);
}
示例7: onActivityResult
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
@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);
}
}
}
示例8: onActivityResult
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
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;
}
}
示例9: onCreate
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
@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();
}
}
});
}
示例10: onActivityResult
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
@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);
}
}
示例11: onActivityResult
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
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();
}
}
}
示例12: onActivityResult
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
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();
}
}
}
}
示例13: onPickEventPlaceClick
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
/**
* 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();
}
}
示例14: onActivityResult
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
@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);
}
}
示例15: onActivityResult
import com.google.android.gms.location.places.ui.PlacePicker; //导入依赖的package包/类
/**
* 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);
}
}