小编k4s*_*k4s的帖子

如何在Android中将自动完成搜索与Google地图集成?

预期结果:在autocomplete小部件中查询将返回在嵌入式Google地图片段中用标记指示的位置。

到目前为止的代码:

活动课:

// Get the SupportMapFragment and request notification
// when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().
        findFragmentById(R.id.mapView);
mapFragment.getMapAsync(this);

PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
        getActivity().getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

EditText attributeText = (EditText)autocompleteFragment.getView().findViewById(R.id.place_autocomplete_search_input);
attributeText.setHint("find your space!");
autocompleteFragment.getView().setBackgroundDrawable(getResources().getDrawable(R.drawable.gradient_search));

autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {

    @Override
    public void onPlaceSelected(Place place) {
        // TODO: Get info about the selected place.
        Log.i(TAG, "Place: " + place.getName());
    }

    @Override
    public void onError(Status status) {
        // TODO: Handle the error.
        Log.i(TAG, "An error occurred: …
Run Code Online (Sandbox Code Playgroud)

java android google-maps google-places-api

3
推荐指数
1
解决办法
1358
查看次数

什么是使用大量布尔开关的替代方法

我有一个旧的代码需要重新使用,它利用了大约10到15个布尔值,这些布尔值在整个类中都跳舞,就像这样:

if (condition)
{
  bool1 = true
}
if (condition)
{
  bool2 = true
}
...
Run Code Online (Sandbox Code Playgroud)

然后

if (bool1 == true && bool2 == true && bool3 == false)
{
  do something
}
else if (bool1 == true && bool2 == false && bool3 == false)
{
  do something
}
...
Run Code Online (Sandbox Code Playgroud)

是否可以避免这种编码方式?有更好的方法来实现这一点吗?也许利用地图?

我想提高可读性和整体性能,因为这段代码长于1,000s行。

反馈后添加更多具体示例:

boolean bool1 = false, bool2 = false, bool3 = false, bool4 = false, bool5 = false,
bool6 = false, bool7 = false, bool8 = false, bool9 …
Run Code Online (Sandbox Code Playgroud)

java theory java-8

0
推荐指数
1
解决办法
679
查看次数

标签 统计

java ×2

android ×1

google-maps ×1

google-places-api ×1

java-8 ×1

theory ×1