現在、私のアプリでGoogleプレイスAPIを使用して、半径5km以内の近くのレストランのクエリを実行しています。しかし、私はユーザーに10kmと25kmの半径で検索する機能を与えたいと思っています。GoogleプレイスSpinnerのSeach
私はそのためにスピナーを使用することに決めました。ユーザーがスピナーから目的の半径を選択し、マップ上の結果を更新できるようにします。しかし、私はそれを動作させることができませんでした、私はいくつかを試してみましたが、失敗しました。
レイアウトファイル
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Restaurants in a"
android:background="#0000"
android:gravity="center"
android:textSize="30dp" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/locateSpinner"></Spinner>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="radius"
android:textSize="30dp"
android:background="#0000"/>
</LinearLayout>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
tools:context="com.test.drawernav.LocateFragment"/>
</LinearLayout>
Javaファイルの関連する部分
@Override
public View onCreate(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner)getActivity().findViewById(R.id.locateSpinner);
spinner.setOnItemSelectedListener(this);
List<String> distances = new ArrayList<String>();
distances.add("5km");
distances.add("10km");
distances.add("25km");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, distances);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
mapFrag = (SupportMapFragment) this.getChildFragmentManager()
.findFragmentById(R.id.map);
mapFrag.getMapAsync(this);
}
public StringBuilder sbMethod(Location currentLocation) {
//current location
double mLatitude = currentLocation.getLatitude();
double mLongitude = currentLocation.getLongitude();
StringBuilder sb = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
sb.append("location=" + mLatitude + "," + mLongitude);
sb.append("&radius=5000");
sb.append("&types=restaurant");
sb.append("&sensor=true");
sb.append("&key=***");
Log.d("Map", "<><>api: " + sb.toString());
return sb;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
私は半径パラメータは、「5000」、「10000」に変更して、私はStringBuilderを別々に実行するために取得する必要があることを知っていますSpinnerから「5km」、「10km」、「25km」が選択された3つのすべてのインスタンスで「25000」と表示されます。私はそれをやり遂げる方法については分かりません。可能な助けを深く感謝します。
このラインに
sb.append("&radius=5000");
にその値を渡します。ダンノーそれは私を攻撃しなかった。どうもありがとう! :) – Devansh助けてもそれをアップアップ –
私はしたが、私は15アップを得るまで私のupvotesは公開されません。申し訳ありません – Devansh