
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);customLocationListener = new CustomLocationListener();locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER,customLocationListener);class CustomLocationListener implements LocationListener{ ............ public voID onLocationChanged(Location argLocation) { if(location != null) { int latitude=(int)(argLocation.getLatitude()*1E6); int longitude=(int)(argLocation.getLongitude()*1E6); } } ........ } 你们中的任何人都知道为什么吗?
注意:我的活动扩展了MapActivity而不是Location Listener
解决方法 试试这种方式locationManager = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); Criteria locationCritera = new Criteria(); String provIDername = locationManager.getBestProvIDer(locationCritera,true); if(provIDername!=null) location = locationManager.getLastKNownLocation(provIDername); locationListener = new MyLocationListener(); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,locationListener);
在mylocationListener中设置您的位置对象
private class MyLocationListener implements LocationListener { public voID onLocationChanged(Location loc) { if (loc != null) { location = loc; } } public voID onProvIDerDisabled(String provIDer) { } public voID onProvIDerEnabled(String provIDer) { } public voID onStatusChanged(String provIDer,int status,Bundle extras) { }} 总结 以上是内存溢出为你收集整理的android – 在地图中显示当前位置时获取纬度和经度0.0全部内容,希望文章能够帮你解决android – 在地图中显示当前位置时获取纬度和经度0.0所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)