Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android地理围栏:转换类型_Android_Geofencing_Android Geofence - Fatal编程技术网

Android地理围栏:转换类型

Android地理围栏:转换类型,android,geofencing,android-geofence,Android,Geofencing,Android Geofence,我正在尝试测试我的android GeoFenging应用程序。我已输入我的当前位置作为地理围栏纬度、位置,并尝试测试应用程序是否工作。从技术上讲,当我运行应用程序时,我处于地理隔离区内。但是,当我启动应用程序时,我没有收到任何通知-当我在地理围栏区域内时,收到的转换类型为-1。还有什么我需要合并的吗?下面是我目前的代码- //once connected to GoogleAPIClient ArrayList<Geofence> geofences = new ArrayLis

我正在尝试测试我的android GeoFenging应用程序。我已输入我的当前位置作为地理围栏纬度、位置,并尝试测试应用程序是否工作。从技术上讲,当我运行应用程序时,我处于地理隔离区内。但是,当我启动应用程序时,我没有收到任何通知-当我在地理围栏区域内时,收到的转换类型为-1。还有什么我需要合并的吗?下面是我目前的代码-

//once connected to GoogleAPIClient

ArrayList<Geofence> geofences = new ArrayList<Geofence>();
geofences.add(new Geofence.Builder()
        .setRequestId("id")
        .setCircularRegion(
                lat, lon, GEOFENCERADIUS)
        .setTransitionTypes(
                Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_DWELL
                        | Geofence.GEOFENCE_TRANSITION_EXIT)
        .setLoiteringDelay(30000) // check every 30 seconds
        .setExpirationDuration(Geofence.NEVER_EXPIRE)
        .build());
        System.out.println("GEOFENCE ADDED");
    }

    GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
    builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
    builder.addGeofences(geofences);

    LocationRequest locationRequest = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY)
            .setFastestInterval(5000L).setInterval(10000L)
            .setSmallestDisplacement(75.0F);

    PendingIntent pendingIntent = PendingIntent.getService(this, 0,
            new Intent(this, GeofenceReceiver.class),
            PendingIntent.FLAG_UPDATE_CURRENT);

    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
            locationRequest, pendingIntent);
//一旦连接到GoogleAppClient
ArrayList geofences=新的ArrayList();
添加(新geofines.Builder()
.setRequestId(“id”)
.setCircularRegion(
纬度、经度、地理半径)
.setTransitionTypes(
Geofence.Geofence_TRANSITION_输入| Geofence.Geofence_TRANSITION_驻留
|土工围栏。土工围栏(过渡段和出口)
.setLoiteringDelay(30000)//每30秒检查一次
.setExpirationDuration(地理围栏永不过期)
.build());
System.out.println(“添加了GEOFENCE”);
}
GeofencingRequest.Builder=新的GeofencingRequest.Builder();
builder.setInitialTrigger(GeofencingRequest.INITIAL\u TRIGGER\u ENTER);
建造商。添加土工围栏(土工围栏);
LocationRequest LocationRequest=LocationRequest.create()
.setPriority(位置请求、优先级、平衡功率、精度)
.SetFastTestInterval(5000L).setInterval(10000L)
.最小位移(75.0F);
PendingEvent PendingEvent=PendingEvent.getService(此,0,
新意图(此,GeofenceReceiver.class),
PendingEvent.FLAG_UPDATE_CURRENT);
LocationServices.FusedLocationApi.requestLocationUpdates(MGoogleAppClient,
位置请求(待定);
意向服务等级如下所示:

public class GeofenceReceiver extends IntentService {

    public GeofenceReceiver()
    {
        super("GeoFenceReceiver");
    }

    @Override
    protected void onHandleIntent(Intent intent) {

        System.out.println("INTENT RECEIVED");

        GeofencingEvent geoEvent=GeofencingEvent.fromIntent(intent);

        if (geoEvent.hasError()) {
               //todo error process
            System.out.println("Error");
        }
        else {
               int transitionType = geoEvent.getGeofenceTransition();

               System.out.println(transitionType);

               if (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER ||
                       transitionType == Geofence.GEOFENCE_TRANSITION_EXIT) {
                   List<Geofence> triggerList = geoEvent.getTriggeringGeofences();

                   for (Geofence geofence : triggerList) {
                       generateNotification(geofence.getRequestId(), "address you defined");
                   }
               }

               if(transitionType==-1)
               {
//                 System.out.println(intent.getAction());
               }
           }
公共类GeofenceReceiver扩展IntentService{
公共地理接收器()
{
超级(“地理接收器”);
}
@凌驾
受保护的手部内容无效(意图){
系统输出打印项次(“收到意向”);
GeofencingEvent geoEvent=GeofencingEvent.fromIntent(intent);
if(geoEvent.hasError()){
//todo错误处理
System.out.println(“错误”);
}
否则{
int transitionType=geoEvent.getGeofenceTransition();
System.out.println(transitionType);
如果(transitionType==geofance.geofance\u TRANSITION\u输入||
transitionType==地理围栏。地理围栏\过渡\退出){
List triggerList=geoEvent.getTriggeringGeofences();
用于(地理围栏地理围栏:触发器列表){
generateNotification(geofence.getRequestId(),“您定义的地址”);
}
}
if(transitionType==-1)
{
//System.out.println(intent.getAction());
}
}
当我运行应用程序时,我收到消息意图,但是,转换类型始终为-1。这是应用程序工作的问题吗


PS:我确信这与GPS精度无关,因为我已将地理围栏半径增加到2公里。因此,我确信这意味着运行应用程序时的过渡。

你要离开围栏进行测试吗?不,我只是试图在围栏区域内生成通知。所以你需要出去获取退出消息所需的给定半径。您可以减小半径,半径应为100米或更大。好的,我将尝试:)谢谢您的建议。我可能遇到了由Google API客户端获取的最后一个位置的问题。由于天气条件差,移动网络无法获取准确位置,因此没有已收到过渡类型。现在一切都很好,正在运行。感谢您的努力。