Android的谷歌地图API的位置位置、地图、Android、API

2023-09-12 10:26:39 作者:爱或不爱i

我GOOGLE了一下周围,仍然无法找到一个明确的答案。

I've googled around a bit, and still can't find a definite answer to this.

什么是当前的最佳或推荐Android中使用谷歌地图的方法是什么?

What is the current "best" or "recommended" way of using Google Maps in Android?

我希望我的应用程序使用的蓝点,可自动跟踪用户的位置,很像地图应用程序确实,当你点击我的位置按钮。其中的一些功能似乎用地图来建刚,但我不能确定如何从这种提取物的位置,因为我读过.getMyLocation()是德precated?

I want my application to use the blue dot that automatically keeps track of the user's location, much like the Maps app does when you click on the "my location" button. Some of this functionality seems to come built in just by using the map, however, I'm unsure how to extract the Location from this, as I've read .getMyLocation() is deprecated?

什么是做到这一点的最好方法是什么?

What is the best way to do this?

推荐答案

我用这code:

//get locationManager object from System Service LOCATION_SERVICE
            LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);


            Criteria criteria = new Criteria();

            String provider = locationManager.getBestProvider(criteria, true);

            Location myLocation = locationManager.getLastKnownLocation(provider);

            map.setMapType(GoogleMap.MAP_TYPE_NORMAL);

            double latitude = myLocation.getLatitude();
            double longitude = myLocation.getLongitude();

            LatLng latLng = new LatLng(latitude, longitude);


            map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10));