使用 GPS/网络 android MapView 获取用户当前位置

发布于 2024-10-17 18:50:29 字数 1245 浏览 7 评论 0原文

您好,我一直在使用本指南来确定用户的位置: http://developer.android.com/guide/topics/location/obtaining-user-location.html

,我当前的代码如下所示:

    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);
}

我只会收到错误,并且当我使用此活动。

感谢您的帮助

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱你是孤单的心事 2024-10-24 18:50:29

请确认您已向清单文件

ACCESS_COARSE_LOCATION 分配以下权限
ACCESS_FINE_LOCATION

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

ACCESS_COARSE_LOCATION
ACCESS_FINE_LOCATION

够钟 2024-10-24 18:50:29

我猜您正在设备中执行此代码,

请在设备

设置 -> 上尝试此操作位置->使用 GPS

设置 ->应用程序设置->发展->允许模拟位置

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

揪着可爱 2024-10-24 18:50:29

我解决了,我没有实例化mapContoller:>。但我现在还有另一个问题。我将在另一个问题中发布。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文