【发布时间】:2016-12-26 22:04:26
【问题描述】:
我在我的 android 应用中实现了 Google 的 PlaceAutocompleteFragment,如下所示。
但我想在最后添加一个按钮,就像谷歌地图有麦克风一样。
以下是我目前的代码:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
>
<fragment
android:id="@+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
/>
</android.support.v7.widget.CardView>
地点选择代码:
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
String placeName = place.getName().toString();
LatLng latLng = place.getLatLng();
mMap.addMarker(new MarkerOptions().position(latLng).title(placeName));
mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
Log.i(TAG, "An error occurred: " + status);
}
});
一个示例代码会很好。非常感谢:)
【问题讨论】:
-
你会添加你的搜索代码
-
我刚做了,你能再看看吗:)
-
我正在查看它并在我的 android studio 上测试它,请给我时间