2 jonskeet JonSkeet 于 2013.03.15 16:28 提问

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

我想根据 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个回答

l445695623
l445695623   2013.03.15 17:06
已采纳

LocationManager.NETWORK_PROVIDER是不是没得到啊,GPS_PROVIDER

dianqiugg
dianqiugg   2013.03.16 09:58

你用的是百度的api么?
有申请申请密钥(key)么
我的资源里有一个demo,你可以拿去看看,不要下载分数

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!