我想知道當他靠近特定位置時是否有任何方式通知用戶。
當用戶靠近位置時,通知到達他的電話,提醒他他的位置。附近的位置通知
我試着下面的代碼,但它不工作。
public class NotifyuserActivity extends Activity {
LocationManager locMan;
double lat;
double lon;
NotificationManager notMan;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locMan=(LocationManager) getSystemService(LOCATION_SERVICE);
locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,10, mylistener);
}
LocationListener的myListener的=新LocationListener的(){
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
lat = location.getLatitude();
lon = location.getLongitude();
CharSequence from = "AlarmManager - Time's up!";
CharSequence message = "This is your alert";
Location tasklocation=new Location(LocationManager.GPS_PROVIDER);
double dis1 = location.distanceTo(tasklocation);
tasklocation.setLatitude(22.727733);
tasklocation.setLongitude(75.886079);
if(dis1 < 200.00)
{
notMan = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification n = new Notification(R.drawable.ic_launcher, "Click here for details", System.currentTimeMillis());
Intent notificationIntent = new Intent(NotifyuserActivity.this,NotifyuserActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(NotifyuserActivity.this, 0, notificationIntent, 0);
n.setLatestEventInfo(NotifyuserActivity.this, from,message, pendingIntent);
notMan.notify(10001, n);
Toast.makeText(NotifyuserActivity.this,"Distance to location is: " + dis1, Toast.LENGTH_LONG).show();
}
}
};
}
我對此並不熟悉,但在測量距離後,您設置了請求的位置(即taskLocation.setLat \ setLong ...)。 另外,你只說,它不工作。它有什麼作用?什麼工作? – 2012-04-29 07:20:28
實際上我想在我的項目中使用此模塊。亞我已經嘗試編寫tasklocation以上DIS,但它也不工作 – shubh 2012-04-29 08:36:35