简体   繁体   English

Android-如何实现此Google Maps动画?

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

相关问题 如何通过 Android Studio 中的 WebView 实现 Google Maps - How can I implement Google Maps through a WebView in Android Studio 如何实现这种自定义的View Wave动画? - How can achieve this custom view wave animation? Android和Google Maps:淡入淡出的脉冲动画 - Android and Google Maps: Fading pulse animation 使用Android中的谷歌地图自定义信息窗口上的动画 - Animation on custom infowindow using google maps in Android 我怎样才能实现android fab快速拨号选择器? - How can I achieve android fab speed dial selector? 如何绘制从我的android应用发送到tomcat服务器的经度和纬度,并在该处的Google地图上进行绘制? - How can i plot the longitudes and latitudes sent from my android app to tomcat server and plot on the google maps there? 我如何绘制从我的 android 应用程序发送到 tomcat 服务器的 lat ,lng 并在那里的谷歌地图上绘制? - How can i plot the lat ,lng sent from my android app to tomcat server and plot on the google maps there? 如何将 Google Maps V2 显示到自定义对话框 android 中 - How I can show Google Maps V2 into a custom dialog android 如何通过使用Google Maps获取用户当前位置并在android中放置标记 - How can i get the user current location and put marker on it in android by using google maps 我怎样才能实现这个代码? - How can I achieve this code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM