2

正如主题所说,我查看了 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
        }
    }

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

4

1 回答 1

1

Nevermind, you do need it, but it can remain empty.

于 2012-08-16T20:32:41.590 回答