Android的谷歌地图API的位置 [英] Android Google Maps API Location

查看:106
本文介绍了Android的谷歌地图API的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我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));

这篇关于Android的谷歌地图API的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆