0

我正在使用我项目中的 MapActivity。

我在主类上有这个 onCreate 方法:

    public class TabMap extends MapActivity implements LocationListener
{
    private MapView mapView;
    private MapController mc;

    private LocationManager lm;

    private double latitude;
    private double longitude;
    private double altitude;
    private float accuracy;

    private MyLocationOverlay myLocation = null;
    private Button select;

    ListInterestPoints currentListofInterest = null;
    String provider;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.onglet_map);

        // instance de l'objet mapView
        mapView = (MapView) this.findViewById(R.id.mapView);

        // ajout des boutons zoom et dezoom
        mapView.setBuiltInZoomControls(true);

        mc = mapView.getController();
        // niveau de zoom a l'initialisation de la map (1->21)
        mc.setZoom(18);

        // instanciation de la classe MyLocationOverlay
        myLocation = new MyLocationOverlay(getApplicationContext(), mapView);

        // ajout de la location a la MAP
        mapView.getOverlays().add(myLocation);

        // afficher le point
        myLocation.enableMyLocation();
        // afficher la boussole
        myLocation.enableCompass();

        // bouton qui repositionne sur la position de l'utilisateur
        select = (Button) findViewById(R.id.googlemaps_select_location);
        select.setOnClickListener(new OnClickListener() 
            {
                public void onClick(View v) 
                {
                    GeoPoint point = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
                    mc.animateTo(point);
                    mc.setCenter(point);
            }});

        // centrage sur la postion de l'utilisateur au 1er lancement
        myLocation.runOnFirstFix(new Runnable() 
        {
            public void run() 
            {
                mc.animateTo(myLocation.getMyLocation());
                mc.setZoom(18);
            }
        });
    }

OnResume 方法:

@Override
    protected void onResume()
    {
        super.onResume();

        lm = (LocationManager) this.getSystemService(LOCATION_SERVICE);
        if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER))
            lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0, this);
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0, this);

        /** Gestion du remplissage des item Shop sur la MAP **/
        if (checkPromotionNotNull() == true)
        {
            // 1er lancement ac list null
            if (currentListofInterest == null)
            {
                putInterestPointsOnMap();
            }
            else
            {
                currentListofInterest.removeAllOverlayItem();
                putInterestPointsOnMap();
            }
        }
        else
        {
            if (currentListofInterest == null){}
            else
                currentListofInterest.removeAllOverlayItem();
        }
    }
    }

我遇到的问题是:我在运行它时收到了这 2 条错误消息(此活动运行良好..):

08-16 14:32:28.390: E/SensorManager(5605): registerListener :: handle = 2  name= Mag & Acc Combo Orientation Sensor delay= 60000 Listener= android.hardware.SensorManager$LegacyListener@405dbf70
08-16 14:32:28.398: E/SensorManager(5605): =======>>>Sensor Thread RUNNING <<<========
08-16 14:32:28.406: E/SensorManager(5605): reg :: handle = 2

08-13 12:37:43.855: I/SensorManager(25211): This application is using deprecated SensorManager API which will be removed someday.  Please consider switching to the new API.

但我不知道你在“新”API中得到它。我对游标管理器做的唯一一件事是:

lm = (LocationManager) this.getSystemService(LOCATION_SERVICE);

进入 onResume().. Somoene 确实有解决它的想法?

4

2 回答 2

3

是因为你打电话myLocation.enableCompass()

这是enableCompassAndroid源代码中Android的实现源代码:

 @Override
    public boolean enableCompass() {
        mCompassEnabled = true;
        mSensorOrientation = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
        mSensorManager.registerListener(this, mSensorOrientation, SensorManager.SENSOR_DELAY_NORMAL);
        return true;
    }

这个使用Sensor.TYPE_ORIENTATION并且该TYPE_ORIENTATION常量现在已被弃用。

所以,这不是你的错,他们在他们之间说话的那些模块,你可以忽略它。

于 2012-08-17T08:51:14.927 回答
0

您的位置侦听器类在哪里:

private final LocationListener locationListener = new LocationListener() 
{ 

    @Override 
    public void onLocationChanged(Location location) { 
        updateWithNewLocation(location); 
    } 

    @Override 
    public void onProviderDisabled(String provider) { 
        updateWithNewLocation(null); 
    } 

    @Override 
    public void onProviderEnabled(String provider) { 
    } 

    @Override 
        public void onStatusChanged(String provider, int status, Bundle extras) { 
    } 

};

你也错过了这部分:

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
于 2012-08-17T08:51:03.243 回答