[英]Android - How can I achieve this Google Maps animation?
This is how I'm currently using my google map; 这就是我目前使用我的Google地图的方式;
mapFragment = ((SupportMapFragment) getChildFragmentManager()
.findFragmentById(R.id.map)).getMap();
mapFragment.setMyLocationEnabled(true);
mapFragment.setMapType(GoogleMap.MAP_TYPE_HYBRID);
mapFragment.getUiSettings().setMapToolbarEnabled(false);
mapFragment.getUiSettings().setScrollGesturesEnabled(false);
mapFragment.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
It produces a full screen map which for some reason is completely zoomed into the ocean so the map is just one big, blue pixel until you keep zooming out. 它会生成一个全屏地图,由于某种原因,它会完全放大到海洋中,因此该地图只是一个大的蓝色像素,直到您继续缩小为止。
What I want to do: 我想做的事:
When this activity gets opened, the map should have the user's location in the center, and the map should be as zoomed out as possible (as if you are lookin at a 2D globe) 打开此活动后,地图应将用户的位置置于中心,并且地图应尽可能缩小(就像您正在查看2D地球一样)
The map should then zoom/animate into the player's location to give the same effect as when you press the location button on the top right of the map. 然后,地图应缩放/动画化播放器的位置,以产生与按地图右上角的位置按钮时相同的效果。
I have looked online, tried a few things and haven't had any luck with this. 我在网上看过,尝试了几件事,对此还没有任何运气。 If anybody can walk me through this or give me a link to a nice guide it would be highly appreciated!
如果有人可以指导我完成这个工作或为我提供一个不错的指南的链接,将不胜感激!
To achieve what you want, you should: 要实现您想要的目标,您应该:
1) get the user's position, you can use the last known position so that your main activity would not hang and wait for the GPS return a location. 1)获取用户的位置,您可以使用最近的已知位置,这样您的主要活动就不会挂起并等待GPS返回位置。
LocationManager locationManager = (LocationManager)getSystemService
(Context.LOCATION_SERVICE);
Location getLastLocation = locationManager.getLastKnownLocation
(LocationManager.PASSIVE_PROVIDER);
2) set the zoom level to 1, which is the smallest zoom level, the 2D globe
; 2)将缩放级别设置为1,这是最小的缩放级别,即
2D globe
; also you can center the map using the user location too. 您也可以使用用户位置将地图居中。
googleMap.moveCamera(CameraUpdateFactory.zoomTo(1));
3) animate the camera to zoom into the user location with a zoom level 20 (the largest zoom level). 3)为相机设置动画,以缩放级别20(最大缩放级别)放大到用户位置。 One thing to notice is that, you might want to wait until the
2D globe
maps is loaded so that user can see the zoom happens. 需要注意的一件事是,您可能要等到加载
2D globe
地图后,用户才能看到缩放发生的情况。
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
public void onMapLoaded() {
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder()
.target(new LatLng(userLocation.getLatitude(), userLocation.getLongitude()))
.zoom(20)
.build()));
}
});
I tried that and it works fine for me. 我尝试了一下,对我来说很好。 Let me know if it is unclear, and hope it helps.
让我知道是否不清楚,希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.