2016-04-27 17 views
0

FYI:我已经搜索了合适的答案,但找不到一个。他们中的大多数都是旧的并且使用了不推荐的方法。当应用启动时,在android谷歌地图中获取当前位置(lat,long)

我需要的是,当应用程序启动时,它会在当前位置显示带有标记的谷歌地图。我可以使用经度和纬度设置标记。但是,我找不到使用GPS获得当前经纬度的任何方法。

请问您能否帮助我使用GPS获取当前经纬度?

在此先感谢。

+0

http://developer.android.com/guide/topics/location/strategies.html – CommonsWare

回答

-1

您可以使用github上提供的GPS Tracker。功能getLongitude()getLatitude()将返回当前位置。

+0

请勿使用此类。它严重地坏了。我们在这里得到了关于为什么它不会一直返回正确结果的问题。我有一个解释它如何破坏http://gabesechansoftware.com/location-tracking/ –

+0

它适用于我,但我会考虑您的帖子。 –

+0

它工作的时间百分比。但是这是有缺陷的代码,不应该向任何人推荐 –

0

这里是我的代码,我用得到我当前的经纬度值:

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
Criteria criteria = new Criteria(); 
Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false)); 
double lat = location.getLatitude(); 
double lng = location.getLongitude(); 

希望这会帮助你。

相关问题