Get user current position with gps/network android MapView

ⅰ亾dé卋堺 提交于 2019-12-08 11:21:22

问题


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 stub

        }
        @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


回答1:


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

ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/5015202/get-user-current-position-with-gps-network-android-mapview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!