似乎无法获得用户位置

时间:2011-09-07 09:24:28

标签: java android

我一直试图通过Android获取用户位置的经度和纬度。我一直在尝试使用LocationManger,但它似乎没有激活并给我一个更新。这是代码,任何想法我做错了什么?

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);// Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {  

        public void onLocationChanged(Location location) {      // Called when a new location is found by the network location provider.      
            System.out.println(location.getLatitude());
            System.out.println(location.getLongitude());
            locationplace = location.getProvider();
            }    
        public void onStatusChanged(String provider, int status, Bundle extras) {}    
        public void onProviderEnabled(String provider) {}    
        public void onProviderDisabled(String provider) {}  };// Register the listener with the Location Manager to receive location updates
    //locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    System.out.println(locationplace);  

0 个答案:

没有答案