![](/img/trans.png)
[英]Android Google Maps: which API used to search places nearby your current location?
[英]How to load google's android places api in your current location
我开始学习Place api。 我设法创建了一个活动,当您单击按钮时,使用地图呈现了places api位置选择器。 我的问题是我可以使用硬编码的LatLangBounds做到这一点,我想要的是渲染地图时从当前位置开始。 我已经使用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();
}
}
});
}
首先,您可以使用Location Services
获取当前职位。 当你有位置,可以采取VisibleRegion
相机地图的,使用该方法onCameraChange()
从地图API。 现在,使用可见区域对象,您可以使用当前位置构造新的LatLngBounds
并调用Places API
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.