我已经在我的android应用中实现了谷歌的PlaceAutocompleteFragment
,它看起来像下面这样。 android - 添加按钮来自动完成搜索框
但我想添加一个按钮,最终谷歌地图有麦克风。
下面是到目前为止我的代码:
<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工作室上测试它,现在只需要给我时间 –