是的,有。您使用位置管理器的addProximityAlert 和BroadcastReveiver。
我会放一些类似于我之前工作的代码的一部分,它应该让你大致了解要搜索的内容......
// IN SOME CLASS, YOU REGISTER BROADCAST RECEIVER FOR SOME COORDINATES
Intent thisIntent = new Intent("my.package.name.MyProximityReceiver"); // MyProximityReceiver is the name of the class where you extend BroadcastReceiver
Bundle thisBundle = new Bundle();
thisBundle.putString("placeName", "SomePlaceName");
thisIntent.putExtras(thisBundle);
PendingIntent proximityIntent = PendingIntent.getBroadcast(getBaseContext(), 0,
thisIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locManager.addProximityAlert(40.218835,-74.000666,
10000 , -1, proximityIntent); // 10000 is the 10km radius , -1 means no expiration, read more in the link provided above
// END OF THAT SOME CLASS YOU ARE REGISTERING BROADCASTRECEIVER IN
// CLASS MyProximityReceiver
public class MyProximityReceiver extends BroadcastReceiver {
public String placeName;
@Override
public void onReceive(Context c, Intent intent) {
Log.d("TAG_IN_BROADCAST", "In broadcast receiver");
String key = LocationManager.KEY_PROXIMITY_ENTERING;
boolean entering = intent.getBooleanExtra(key, false);
Bundle thisBundle = intent.getExtras();
if (thisBundle != null)
{
placeName = thisBundle.getString("placeName");
}
if (entering)
{
Log.e("TAG_ENTERING","ENTERING");
// SOMEONE ENTERED THE AREA
}
else
{
Log.e("TAG_LEAVING", "LEAVING");
// SOMEONE EXITED THE AREA
}
...
...
}
....
}
这可能不起作用(这些只是代码的一部分),但这只是为了让您了解如何做您想做的事情......
希望这会有所帮助...