我想知道当他靠近特定位置时是否有任何方式通知用户。
当用户靠近位置时,通知到达他的电话,提醒他他的位置。附近的位置通知
我试着下面的代码,但它不工作。
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