我目前正在使用"Regions"示例代码:https: //developer.apple.com/library/ios/#samplecode/Regions/Introduction/Intro.h tml#// apple_ref/doc/uid/DTS40010726-Intro-DontLinkElementID_2
我想更进一步,当用户退出该区域时生成或触发通知(可以同时进入和退出,我不介意,对于初始实现最简单的事情).
我一直在查看CLLocation类参考,位置感知编程指南以及本地和推送通知编程指南.而我正在遭受信息超载.
非常感谢 :)
编辑:我想我可能有一个解决问题的想法:在RegionsViewController实现文件中有这样的:
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
NSString *event = [NSString stringWithFormat:@"didExitRegion %@ at %@", region.identifier, [NSDate date]];
[self updateWithEvent:event];
}
Run Code Online (Sandbox Code Playgroud)
由于我想在用户退出指定区域边界时实现本地通知,我输入了以下内容:
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
NSString *event = [NSString stringWithFormat:@"didExitRegion %@ at %@", region.identifier, [NSDate date]];
[self updateWithEvent:event];
//implement local notification:
UIApplication *app = [UIApplication sharedApplication];
UILocalNotification *notification = [[UILocalNotification alloc] init];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
if (notification == nil)
return;
notification.alertBody = [NSString stringWithFormat:@"Did You Lock Your …Run Code Online (Sandbox Code Playgroud) 我的代码在我的iPhone上创建了一个地理围栏,它会在调用didExitRegion时触发一些代码.但是,我发现当我关闭WiFi时,didExitRegion永远不会被触发.是否需要WiFi来监控iOS上的区域变化?我想要的准确度设置为kCLLocationAccuracyHundredMeters.我正在测试iOS 6.1和iPhone 4.
以下是我设置位置监控的代码:
- (id)init {
self = [super init];
if (self) {
CLLocationManager *manager = [[CLLocationManager alloc] init];
manager.delegate = self;
manager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
manager.distanceFilter = RADIUS/10.0;
manager.headingFilter = kCLHeadingFilterNone;
self.locationManager = manager;
self.authorizationStatus = [CLLocationManager authorizationStatus];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我的应用使用地理围栏并发送通知.
默认情况下,设置 - 应用程序的通知中的声音已关闭.
iOS 7准确无误.
有谁知道如何解决这一问题?
以下是负责此操作的代码:
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = [NSDate dateWithTimeInterval:5 sinceDate:[NSDate date]];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = [NSString stringWithFormat:@"You are near %@. Don't forget to check in!",place.name];
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
Run Code Online (Sandbox Code Playgroud) 我已经设置了一个只有区域监控而没有其他内容的应用.我正在通过在前台模式下运行进行测试(与后台模式相反).它运行在带有ios 7.0.4的iphone 5上.它具有后台应用程序刷新和位置服务以及启用此应用程序的位置授权.
我发现了一些非常奇怪的事情.当我使用模拟器跨越边界时,有时didEnterRegion/ didExitRegion被调用.但有时候,无论我在模拟中切入和跳出边界多少次,它都不会被调用.有些时候,在我改变模拟后,它被称为显着延迟(几分钟).
我检查monitoredRegions确保我想监视的区域是有效的,它是.受监测的区域半径约为100米.我使用2个模拟点,1个内部,1个在不同的城市.我用来startMonitoringForRegion监控这个地区.
我在这里错过了什么吗?
我希望在Android的Cordova/PhoneGap 3.0应用程序中添加一些Geofencing.
有没有人有使用任何插件的经验?或者,如果您可以建议以有效的方式在我的应用程序内部计算地理围栏的最佳方法?
现在我拥有它,以便它每5秒自动更新一次,并根据本地代码中的预定义点进行检查,如果用户是否在半径范围内.只是它似乎有点对系统负担.任何建议都很棒!
先感谢您!
我有一个华硕Eee Tab(Transformer Prime TF201 Android v4.1.1).我正在阅读关于Geofencing的API并将下面的示例应用程序下载到我的设备=> http://developer.android.com/training/location/geofencing.html.但是当我打开它时它会终止.
我在AndroidManifest.xml文件中设置了目标sdk = 16
logcat的
06-04 19:39:34.176: E/AndroidRuntime(2596): FATAL EXCEPTION: main
06-04 19:39:34.176: E/AndroidRuntime(2596): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.geofence/com.example.android.geofence.MainActivity}: java.lang.ClassNotFoundException: com.example.android.geofence.MainActivity
06-04 19:39:34.176: E/AndroidRuntime(2596): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
06-04 19:39:34.176: E/AndroidRuntime(2596): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
06-04 19:39:34.176: E/AndroidRuntime(2596): at android.app.ActivityThread.access$600(ActivityThread.java:130)
06-04 19:39:34.176: E/AndroidRuntime(2596): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
06-04 19:39:34.176: E/AndroidRuntime(2596): at android.os.Handler.dispatchMessage(Handler.java:99)
06-04 19:39:34.176: E/AndroidRuntime(2596): at android.os.Looper.loop(Looper.java:137)
06-04 19:39:34.176: E/AndroidRuntime(2596): at android.app.ActivityThread.main(ActivityThread.java:4745)
06-04 19:39:34.176: E/AndroidRuntime(2596): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 19:39:34.176: E/AndroidRuntime(2596): at java.lang.reflect.Method.invoke(Method.java:511)
06-04 19:39:34.176: E/AndroidRuntime(2596): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) …Run Code Online (Sandbox Code Playgroud) android geolocation classnotfoundexception geofencing android-geofence
我对Google Play Services 6.1.71没有任何问题(因为一切正常)但与新版本(6.5.87)不一样.
我已经知道LocationClient在6.5.87 Google Play Services课程中不推荐使用类,我在转换旧的GeofenceDetection示例时几乎没有问题.
OnAddGeofencesResultListener,OnRemoveGeofencesResultListener而且我曾经在控制台上处理错误;我修改过的代码是:
ReceiveTransitionsIntentService.java
public class ReceiveTransitionsIntentService extends IntentService {
/**
* Sets an identifier for this class' background thread
*/
public ReceiveTransitionsIntentService() {
super("ReceiveTransitionsIntentService");
}
/**
* Handles incoming intents
*
* @param intent The Intent sent by Location Services. This Intent is provided
* to Location Services (inside a PendingIntent) when you call addGeofences()
*/
@Override
protected void onHandleIntent(Intent intent) { …Run Code Online (Sandbox Code Playgroud) java android google-api-client geofencing google-play-services
我正在尝试创建一个具有单个按钮的新地理围栏应用程序(Toast消息"inside"或"outside"),但应用程序在启动时崩溃.
这是代码:
MainActivity.java
package com.example.geofencing;
import java.util.ArrayList;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.Geofence;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.IntentSender;
import android.location.Location;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
// save the string that represent the geofence status
private static String DWELL = "Default";
private GoogleApiClient mGoogleClient;
// mock laoctions variables
private static final String PROVIDER = "flp";
private static final double LAT …Run Code Online (Sandbox Code Playgroud) 我正在尝试测试GeoFences的位置感知应用程序.我已经获得了多达11次连续成功,但通常会有数十次失败.重新启动设备没有帮助.卸载/重新安装没有帮助.禁用位置,重新启用位置无济于事.更改设备位置准确度设置没有帮助.
我已经在v2.3.4,v4.0.3,v4.4.2,v4.4.4和2 v5.0.1物理设备上进行了测试.其中一个Lollipop设备是具有蜂窝服务的设备.其余设备是SIMless的,仅用于测试.旁注:没有服务的设备很难通过MockLocation设置它们的位置,但是如果他们设法设置它们的位置,他们几乎从不注册围栏入口/出口.
位置正在通过Mock Location更新,但GeoFence不会被任何可靠性触发.
我用谷歌搜索了它.我查看了developer.android.com网站上的文档.我搜索过StackOverflow.事实上,其他人提出的许多建议已在下面的代码中实现.
那么,我如何使用MockLocation可靠地触发我的GeoFence?
import android.location.Location;
import android.location.LocationManager;
public class GeoFenceTester extends ActivityInstrumentationTestCase2<GeoFenceTesterActivity> {
public static final String TAG = GeoFenceTester.class.getSimpleName();
private LocationManager locationManager;
private Activity activityUnderTest;
protected void setUp() throws Exception {
super.setUp();
activityUnderTest = getActivity();
/*
MOCK Locations are required for these tests. If the user has not enabled MOCK Locations
on the device or emulator these tests cannot work.
*/
if (Settings.Secure.getInt(activityUnderTest.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION, 0) == 0) {
throw new RuntimeException("Mock locations are currently disabled …Run Code Online (Sandbox Code Playgroud) android unit-testing geolocation android-location geofencing
我尝试在用户到达定义的区域时向其显示推送警报。
所以我从以下网址对我的应用进行了编码:https : //developer.android.com/training/location/geofencing
如果我的应用程序按照用户的位置运行并带有服务,则运行良好。
例如,如果我启动google map,它也可以工作,它也可以跟踪我的位置。推送将出现。
但是,如果我关闭我的应用程序,则不会出现该推送,因此如果没有应用程序在跟踪我的位置,则不会检测到地理围栏。
正常吗?如何使其始终有效?如果需要在您所在的位置跟随前台服务,地理围栏的目的是什么?
public void createGeofenceAlerts(LatLng latLng, int radius) {
final Geofence enter = buildGeofence(ID_ENTER, latLng, radius, Geofence.GEOFENCE_TRANSITION_ENTER);
final Geofence exit = buildGeofence(ID_EXIT, latLng, radius, Geofence.GEOFENCE_TRANSITION_EXIT);
final Geofence dwell = buildGeofence(ID_DWELL, latLng, radius, Geofence.GEOFENCE_TRANSITION_DWELL);
GeofencingRequest request = new GeofencingRequest.Builder()
.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER)
.addGeofence(enter)
.addGeofence(exit)
.addGeofence(dwell)
.build();
fencingClient.addGeofences(request, getGeofencePendingIntent()).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Timber.i("succes");
Toast.makeText(mContext, "Geofence added", Toast.LENGTH_LONG).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Timber.e(e,"failure"); …Run Code Online (Sandbox Code Playgroud) geofencing ×10
android ×6
geolocation ×5
ios ×3
iphone ×2
background ×1
cordova ×1
crash ×1
geocoding ×1
html5 ×1
ios7 ×1
java ×1
location ×1
maps ×1
objective-c ×1
unit-testing ×1
wifi ×1