本文介绍了它是更多钞票,以获得在Android的图形页面的当前位置,而无需使用位置监听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个图形页面的应用程序。当应用程序启动它应该显示的当前位置。如何做到这一点?
I have a MapView application. When application launches it should show the current location. How to do this?
推荐答案
试试这个
public class MyLocationOnMap extends MapActivity {
private LocationManager hdLocMgr;
private String hdLocProvider;
onCreate(...) {
:
Criteria hdCrit = new Criteria();
hdCrit.setAccuracy(Criteria.ACCURACY_COARSE);
hdCrit.setAltitudeRequired(false);
hdCrit.setBearingRequired(false);
hdCrit.setCostAllowed(true);
hdCrit.setPowerRequirement(Criteria.POWER_LOW);
hdLocMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
hdLocProvider = hdLocMgr.getBestProvider(hdCrit, true);
Location location = hdLocMgr.getLastKnownLocation(hdLocProvider);
Double dlat = location.getLatitude();
Double dlon = location.getLongitude();
:
}
}
这篇关于它是更多钞票,以获得在Android的图形页面的当前位置,而无需使用位置监听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!