我有一个Google活动,我希望一旦地图打开/蓝点出现,相机就会对用户进行对焦和放大,这样用户就不必按下“中心”按钮,也不必硬编码地图摄像机的位置。
我发现了很多5-6岁的代码示例,所以它们都不再起作用了。
是否可能获得当前用户的位置(lat )。而且很长。)更多?
发布于 2018-11-01 21:58:18
请试试这个:
private void centerOnMyLocation() {
map.setMyLocationEnabled(true);
location = map.getMyLocation();
if (location != null) {
myLocation = new LatLng(location.getLatitude(),
location.getLongitude());
}
map.animateCamera(CameraUpdateFactory.newLatLngZoom(myLocation,
Constants.MAP_ZOOM));
}更新属性名称并调用此代码以当前用户的位置为中心。
如果您已经有了当前的职位,只需调用此功能:
map.animateCamera(CameraUpdateFactory.newLatLngZoom(myLocation,
Constants.MAP_ZOOM));发布于 2018-11-01 22:56:45
首先,您需要一个LatLngBounds对象,这是必要的,这样您就可以定义绑定映射的位置。
然后,您需要定义设备的宽度和高度,这非常简单。
只需遵循下面的代码
LatLngBounds.Builder builder = new LatLngBounds.Builder();
//Insert your location
builder.include(location1);
builder.include(location2);
LatLngBounds bounds = builder.build();
//Get the width and height of the device's screen
int width = getResources().getDisplayMetrics().widthPixels;
int height = (int) ((getResources().getDisplayMetrics().heightPixels) * 0.85);
int padding = (int) (width * 0.15);
//Centralize the markers
yourMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding));https://stackoverflow.com/questions/53109835
复制相似问题