Google Places API会查找距离为10英里的位置

时间:2016-03-22 16:32:31

标签: java android android-studio google-places-api

我创建了一个应用程序,可以使用Google地方查找我所在区域附近的所有地方。然而,它只给出了真正靠近我所在位置的地方,我希望能找到半径10英里范围内的地方。有没有办法做到这一点?

我的代码就像休耕一样

PlacePickerActivity

   private static final int PLACE_PICKER_REQUEST = 19;


    private TextView mName;
    private TextView mAddress;
    private TextView mAttributions;
    private TextView mNumber;
    private TextView car;
    private static final LatLngBounds Sligo = new LatLngBounds(
            new LatLng(54.27, -8.47), new LatLng(54.27, -8.47));

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_place_picker);
        mName = (TextView) findViewById(R.id.textView);
        mAddress = (TextView) findViewById(R.id.textView2);
        mAttributions = (TextView) findViewById(R.id.textView3);
        mNumber = (TextView) findViewById(R.id.textView4);
        Button pickerButton = (Button) findViewById(R.id.pickerButton);
        pickerButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                try {
                    PlacePicker.IntentBuilder intentBuilder =
                            new PlacePicker.IntentBuilder();
                    intentBuilder.setLatLngBounds(Sligo);


                        List<Integer> filterTypes = new ArrayList<Integer>();
                        filterTypes.add(Place.TYPE_CAR_REPAIR);


                    Intent intent = intentBuilder.build(PlacePickerActivity.this);
                    startActivityForResult(intent, PLACE_PICKER_REQUEST );
                } catch (GooglePlayServicesRepairableException
                        | GooglePlayServicesNotAvailableException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode,
                                    int resultCode, Intent data) {

        if (requestCode == PLACE_PICKER_REQUEST
                && resultCode == Activity.RESULT_OK) {

            final Place place = PlacePicker.getPlace(this, data);
            final CharSequence name = place.getName();
            final CharSequence address = place.getAddress();
            final CharSequence formatted_phone_number = place.getPhoneNumber();

        //    final CharSequence car = place.TYPE_CAR_REPAIR();
           //public abstract List<Integer> getTypeFilter(place.TYPE_CAR_REPAIR);
            String attributions = (String) place.getAttributions();
            if (attributions == null) {
                attributions = "";
            }

            mName.setText(name);
            mAddress.setText(address);
            mAttributions.setText(Html.fromHtml(attributions));
            mNumber.setText(formatted_phone_number);



        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }

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:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                android:paddingBottom="@dimen/activity_vertical_margin"
                tools:context=".PlacePickerActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:layout_alignParentTop="true"
        android:layout_marginTop="20dp"
        android:layout_centerHorizontal="true"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView2"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Launch Places API Picker"
        android:id="@+id/pickerButton"
        android:layout_below="@+id/textView2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView3"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView4"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/textView2"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"/>


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView3"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:id="@+id/poweredBy"
        android:src="@drawable/powered_by_google_light"/>

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginBottom="-20dp"
        android:layout_above="@+id/poweredBy"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:id="@+id/truiton_image"
        android:src="@mipmap/truiton_short_no_back"/>
</RelativeLayout>

0 个答案:

没有答案