0
我正在嘗試根據選定標記的位置設置接近警報,該標記的座標存儲在外部文件中,並讀入數組中,然後繪製數組該座標。感應警報類不會觸發Android
googleMap.setOnInfoWindowClickListener(
new OnInfoWindowClickListener(){
public void onInfoWindowClick(Marker marker) {
LatLng clickedMarkerLatLng = marker.getPosition();
double lat = clickedMarkerLatLng.latitude;
double long1 = clickedMarkerLatLng.longitude;
Log.e("hello", "Output=" + lat + long1);
LocationManager lm;
// double lat=0;
// double long1=0; //Defining Latitude & Longitude
float radius=3000;
lm=(LocationManager) getSystemService(LOCATION_SERVICE);
Intent i= new Intent("com.example.sleepertrain5.proximityalert"); //Custom Action
PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), -1, i, 0);
lm.addProximityAlert(lat, long1, radius, -1, pi);
Toast.makeText(getBaseContext(),
"Info Window [email protected]" + lat + "dddjdj" + long1,
Toast.LENGTH_SHORT).show();
class ProximityReceiver extends android.content.BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
// The reciever gets the Context & the Intent that fired the broadcast as arg0 & agr1
String k=LocationManager.KEY_PROXIMITY_ENTERING;
// Key for determining whether user is leaving or entering
boolean state=arg1.getBooleanExtra(k, false);
//Gives whether the user is entering or leaving in boolean form
if(state){
// Call the Notification Service or anything else that you would like to do here
Toast.makeText(arg0, "Welcome to my Area", 600).show();
}else{
//Other custom Notification
Toast.makeText(arg0, "Thank you for visiting my Area,come back again !!", 600).show();
}
}
}
}
});
}
所選標記的座標被傳遞給位置管理器,但接近報警不起作用。顯然此刻,它只是顯示敬酒,但它甚至沒有這樣做。根據日誌,Proximity接收器類永遠不會被調用,但我無法弄清楚爲什麼。我已經嘗試過使用不同尺寸的半徑,但它仍然不起作用。任何想法或幫助?