简体   繁体   English

如何在当前位置加载Google的Android Places API

[英]How to load google's android places api in your current location

I am starting to learn places api. 我开始学习Place api。 I managed to create an activity and when you click the button renders the places api location picker with a map. 我设法创建了一个活动,当您单击按钮时,使用地图呈现了places api位置选择器。 My problem is I can do this with a hardcoded LatLangBounds, what I want is when I render the map is to start on my current location. 我的问题是我可以使用硬编码的LatLangBounds做到这一点,我想要的是渲染地图时从当前位置开始。 I have done this using maps api but for this places api I am confused. 我已经使用maps api做到了,但是对于这个地方api我很困惑。

private static final int PLACE_PICKER_REQUEST = 1;
private TextView mName;
private TextView mAddress;
private TextView mAttributions;
private static final LatLngBounds BOUNDS_HARD_CODED_LOCATION = new LatLngBounds(
        new LatLng(37.398160, -122.180831), new LatLng(37.430610, -121.972090));

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_place_picker);

    /**
     * not part of places api standard code to add back function to action bar
     */
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mName = (TextView) findViewById(R.id.textView);
    mAddress = (TextView) findViewById(R.id.textView2);
    mAttributions = (TextView) findViewById(R.id.textView3);
    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(BOUNDS_HARD_CODED_LOCATION );
                Intent intent = intentBuilder.build(PlacePickerActivity.this);
                startActivityForResult(intent, PLACE_PICKER_REQUEST);

            } catch (GooglePlayServicesRepairableException
                    | GooglePlayServicesNotAvailableException e) {
                e.printStackTrace();
            }
        }
    });
}

First, you can obtain your current position using the Location Services . 首先,您可以使用Location Services获取当前职位。 When you have the position, you can take the VisibleRegion of the camera map, using the method onCameraChange() from the maps API. 当你有位置,可以采取VisibleRegion相机地图的,使用该方法onCameraChange()从地图API。 Now with the visible region object you can construct new LatLngBounds with your current position and call the Places API 现在,使用可见区域对象,您可以使用当前位置构造新的LatLngBounds并调用Places API

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android 谷歌地图:哪个 API 用于搜索您当前位置附近的地方? - Android Google Maps: which API used to search places nearby your current location? Google的LocationSettings放置api以检测当前位置 - LocationSettings for Google places api to detect current location 使用Android中的Google Maps API显示当前位置和附近地点以及两个地点之间的路线 - Show Current Location and Nearby Places and Route between two places using Google Maps API in Android 如何使用Android中的Google Maps Api获取手机的当前位置? - How to get my phone's current location using Google Maps Api in Android? 获取我当前位置的Google Places API(位置搜索)的名称 - Getting name of google places API (Place Search) for my current location 使用Google Places API时从当前位置获取建议 - Getting the Suggestions from the Current Location when working with Google Places API 如何在Android应用程序中使用Google的自动完成放置api - How to use Google's auto complete places api in Android application 使用 Android 中的 Google Maps API 从用户位置获取附近地点的结果 - Getting results of nearby places from User's Location using Google Maps API in Android 如何在android中创建一个应用程序以查找离您的位置最近的地方 - How to create an app in android that find places nearest your location 如何从Google+ API for Android获取当前位置? - How to get current location from Google+ API for Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM