locationManager.addProximityAlert是否需要位置侦听器

时间:2012-08-16 00:46:45

标签: android locationmanager proximity

正如主题所说,我查看了Android开发人员指南,但无法找到答案。如果您只想知道何时进入某个区域,Proximity警报是否需要位置监听器?我正在设置接近警报,如下所示:

private void addProximityAlert(double latitude, double longitude) {

        Intent intent = new Intent(PROX_ALERT_INTENT);
        PendingIntent proximityIntent = PendingIntent.getBroadcast(this, 0,
                intent, 0);

        locationManager.addProximityAlert(latitude, longitude, POINT_RADIUS,
                PROX_ALERT_EXPIRATION, proximityIntent);

        IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT);
        proxalert = new ProximityIntentReceiver();
        registerReceiver(proxalert, filter);
    }

然后调用如下:

addProximityAlert(SMASH_LAT, SMASH_LNG);

问题是,我是否需要以下内容?

locationManager.requestLocationUpdates(
                // check every 10 minutes
                low.getName(), MINIMUM_TIME_BETWEEN_UPDATE,
                MINIMUM_DISTANCECHANGE_FOR_UPDATE, new MyLocationListener());


public class MyLocationListener implements LocationListener {
        @Override
        public void onLocationChanged(Location location) {
            Location pointLocation = retrievelocation();
            float distance = location.distanceTo(pointLocation);
            // txted.setText("Distance: " + distance);
        }

        @Override
        public void onStatusChanged(String s, int i, Bundle b) {
        }

        @Override
        public void onProviderDisabled(String s) {
            // try switching to a different provider
        }

        @Override
        public void onProviderEnabled(String s) {
            // try switching to a different provider
        }
    }

或者,locationmanager是否已经从网络/ gps处理位置更新,然后知道它何时在邻近区域?

1 个答案:

答案 0 :(得分:1)

没关系,你确实需要它,但它可以保持空白。