Java源码示例:com.google.android.gms.location.places.ui.PlaceAutocomplete
示例1
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.
}
}
示例2
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.
}
}
示例3
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.
}
}
示例4
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.
}
}
示例5
@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());
}
}
示例6
public void onActivityResultSuccesful(int requestCode, Intent data) {
if(requestCode == 1) {
onAddressFromReceived(String.valueOf(PlaceAutocomplete.getPlace(mFragmentActivity, data).getAddress()));
onFromLatLngReceived(PlaceAutocomplete.getPlace(mFragmentActivity, data).getLatLng().latitude,
PlaceAutocomplete.getPlace(mFragmentActivity, data).getLatLng().longitude);
sendFromAddressString();
} else if(requestCode == 2) {
onAddressToReceived(String.valueOf(PlaceAutocomplete.getPlace(mFragmentActivity, data).getAddress()));
onToLatLngReceived(PlaceAutocomplete.getPlace(mFragmentActivity, data).getLatLng().latitude,
PlaceAutocomplete.getPlace(mFragmentActivity, data).getLatLng().longitude);
sendToAddressString();
}
}
示例7
/**
* 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.
}
}
}