为了账号安全,请及时绑定邮箱和手机立即绑定

如何获取用户的当前位置?

如何获取用户的当前位置?

慕沐林林 2019-03-13 14:15:17
我想根据 Network Provider 获取用户的当前位置,但是没有成功,UpdateLocation()方法也没有被调用。 如何获取用户的当前位置?public void UpdateLocation(Location location) {     GeoPoint geoPoint = new GeoPoint((int)(location.getLatitude() * 1E6),(int)(location.getLongitude() * 1E6));     MapController controller = mapView.getController();     controller.setCenter(geoPoint); } public void GetLocation() {      // Acquire a reference to the system Location Manager     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.           UpdateLocation(location);         }         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); }
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 894 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号