在Android应用中找到lat和lon

时间:2014-11-05 21:55:49

标签: android android-activity gps android-location

我需要在活动中获得lat和lon。在我的oncreate方法中,我尝试了下面的代码但是当我尝试打印Lat时,我没有得到任何东西。我究竟做错了什么。我也包含在清单文件中。我需要两个值为Lat和lon

的字符串
LocationManager manager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

             LocationListener lis = new LocationListener(){

                @Override
                public void onLocationChanged(Location location) {
                    // TODO Auto-generated method stub
                    Log.d("", "location " + location.getLatitude());

                }

                @Override
                public void onStatusChanged(String provider, int status,
                        Bundle extras) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onProviderEnabled(String provider) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onProviderDisabled(String provider) {
                    // TODO Auto-generated method stub

                }


            };


            manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, lis);

0 个答案:

没有答案