开发者

Cannot seem to get user location

I've been trying to get the longitude and latitude of a users location with Android. I've been trying to use the LocationManger however it does not seem to activate and give me an update. Here is the code, any ideas what I'm doing wrong?

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开发者_JAVA技巧());
            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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜