目前,地点选择器显示地图上标有所有地点的地图。地点列表位于屏幕底部。
如果按地点类型过滤地点会很棒。
例如,地图和列表只会显示附近的出租车站。
我的java代码:
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.widget.Toast;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlacePicker;
public class PlacesAPIActivity extends AppCompatActivity {
private int PLACE_PICKER_REQUEST = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_places_api);
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
Intent intent;
try {
intent = builder.build(getApplicationContext());
startActivityForResult(intent, PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_place_api, menu);
return true;
}
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 %s", place.getName(), place.getPhoneNumber());
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
}
}
}
}
我的XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:background="@drawable/bg_gradient">
答案 0 :(得分:0)
此功能目前无法使用。您可以按照这些未解决的问题进行更新:
答案 1 :(得分:0)
a解决方法可能是检查PlaceType并采取相应的操作:
if (!place.getPlaceTypes().contains(1013)){ // 1013 = point of interest
// Do action if Selected place not a point of interest
}