[英]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.