如何知道位置管理器中的请求位置更新方法是否在Android模拟器中使用最小时间



在这里我做了一个程序,我将请求位置更新方法中的时间设置为 61000 毫秒,因此从 DDMS 中的模拟器中,我更改了位置 lati 和 longi,但 dnt 按下发送按钮。 现在 61 秒后,为什么不在 61 秒后自动更新模拟器中新插入的 LAT Long。

这是我的代码...

package com.getlocation;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
public class ShowMap extends MapActivity 
{
    TextView tv;
    /*private MapController mapController;
    private MapView mapView;*/
    private LocationManager locationManager;
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.main); // bind the layout to the activity
        tv=(TextView) findViewById(R.id.textView1);
        // create a map view
        //RelativeLayout linearLayout = (RelativeLayout) findViewById(R.id.mainlayout);
        //mapView = (MapView) findViewById(R.id.mapview);
        //mapView.setBuiltInZoomControls(true);
        //mapView.setStreetView(true);
        //mapController = mapView.getController();
        //mapController.setZoom(14); // Zoon 1 is world view
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 61000,
                10, new GeoUpdateHandler());
    }
    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
    public class GeoUpdateHandler implements LocationListener {
        @Override
        public void onLocationChanged(Location location) {
            int lat = (int) (location.getLatitude() * 1E6);
            int lng = (int) (location.getLongitude() * 1E6);
            GeoPoint point = new GeoPoint(lat, lng);
            //mapController.animateTo(point); //    
            //mapController.setCenter(point);
            tv.setText(String.valueOf(lat));
            tv.append("n"+String.valueOf(lng));
            Log.d("Tag", "Starting update");
        }
        @Override
        public void onProviderDisabled(String provider) {
        }
        @Override
        public void onProviderEnabled(String provider) {
        }
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    }
}

@saurabh模拟器无法自动检测位置,但如果我们提供纬度和经度并按发送按钮,它会检测位置

您在requestLocationUpdate中提供初始纬度和经度,并设置最小时间和距离,以便它可以工作,但是如果不提供纬度和经度,它就无法理解新位置,然后按发送按钮

所以最好的测试是在设备上

祝你好运

最新更新