开发者

Get user current position with gps/network android MapView

开发者 https://www.devze.com 2023-02-11 13:43 出处:网络
Hello I\'ve been using this guide to determine the locationof the user: http://developer.android.com/guide/topics/location/obtaining-user-location.html

Hello I've been using this guide to determine the locationof the user: http://developer.android.com/guide/topics/location/obtaining-user-location.html

and my current code looks like this:

    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            test = new GeoPoint((int)location.getLatitude()*1000000, (int)location.getAltitude()*1000000);
            mapController.animateTo(test);
        }

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

        }
        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method st开发者_StackOverflow社区ub

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

        }
    };
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}

I only get error and the app shuts down though when I'm using this activity.

Thankful for help


PLease confirm that you have alloted the following permission to your manifest file

ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION


I guess you are executing this code in the device

try this on device

Setting -> Location -> Use GPS

AND

Setting -> Application Settings -> Development -> Allow Mock Location


I solved it, I didn't instantiate mapContoller :>. But I've another problem now. which I will post in another question.

0

精彩评论

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