使用 GPS/网络 android MapView 获取用户当前位置
您好,我一直在使用本指南来确定用户的位置: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请确认您已向清单文件
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
我猜您正在设备中执行此代码,
请在设备
设置 -> 上尝试此操作位置->使用 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
我解决了,我没有实例化mapContoller:>。但我现在还有另一个问题。我将在另一个问题中发布。
I solved it, I didn't instantiate mapContoller :>. But I've another problem now. which I will post in another question.