功能点:

  • 使用高德地图实现地理围栏功能
  • 可设置手机号和短信间隔,设置后间隔发送当前位置
  • 可地图选点设置地理围栏
  • 离开进入地理围栏会有相应短信提醒(设置手机号并获取权限后)





关键代码

public class MainActivity extends BaseActivityimplements NavigationView.OnNavigationItemSelectedListener,View.OnClickListener,GeoFenceListener,AMap.OnMapClickListener,LocationSource,AMapLocationListener,CompoundButton.OnCheckedChangeListener {private View lyOption;private TextView tvGuide;private TextView tvResult;private EditText etRadius;private CheckBox cbAlertIn;private CheckBox cbAlertOut;private CheckBox cbAldertStated;private Button btAddFence;private Button btOption;private AMapLocationClient mlocationClient;private LocationSource.OnLocationChangedListener mListener;private AMapLocationClientOption mLocationOption;private MapView mMapView;private AMap mAMap;// 中心点坐标private LatLng centerLatLng = null;// 中心点markerprivate Marker centerMarker;private BitmapDescriptor ICON_YELLOW = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW);private BitmapDescriptor ICON_RED = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED);private MarkerOptions markerOption = null;private List<Marker> markerList = new ArrayList<Marker>();// 当前的坐标点集合,主要用于进行地图的可视区域的缩放private LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();// 地理围栏客户端private GeoFenceClient fenceClient = null;// 要创建的围栏半径private float fenceRadius = 0.0F;// 触发地理围栏的行为,默认为进入提醒private int activatesAction = GeoFenceClient.GEOFENCE_IN;// 地理围栏的广播actionprivate static final String GEOFENCE_BROADCAST_ACTION = "com.example.geofence.round";// 记录已经添加成功的围栏private HashMap<String, GeoFence> fenceMap = new HashMap<String, GeoFence>();private View map_top;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);requestPermission();initView();initMap(savedInstanceState);}private void requestPermission() {Acp.getInstance(this).request(new AcpOptions.Builder().setPermissions(Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_PHONE_STATE).build(),new AcpListener() {@Overridepublic void onGranted() {}@Overridepublic void onDenied(List<String> permissions) {ToastUtil.show(MainActivity.this,"权限不够,应用可能会出现问题");}});}private void initView() {Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);setSupportActionBar(toolbar);FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);fab.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {sendMessage();}});DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);drawer.addDrawerListener(toggle);toggle.syncState();NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);navigationView.setNavigationItemSelectedListener(this);View headerView = navigationView.getHeaderView(0);TextView user = (TextView) headerView.findViewById(R.id.user_textview);String userid = SpUtil.getString(ConstantValue.USER_LOGIN_INFO, "");user.append(userid+"");}private void sendMessage() {if (ContextCompat.checkSelfPermission(this,Manifest.permission.SEND_SMS)!= PackageManager.PERMISSION_GRANTED) {showMissingPermissionDialog();}else{//startMessage();}}private void showMissingPermissionDialog() {android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this);builder.setTitle(R.string.notifyTitle);builder.setMessage(R.string.notifyMsg);// 拒绝, 退出应用builder.setNegativeButton(R.string.cancel,new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {finish();}});builder.setPositiveButton(R.string.setting,new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {startAppSettings();}});builder.setCancelable(false);builder.show();}private void startMessage() {handler.post(runnable);}private int sendMessageDelay = 60000;Runnable runnable=new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stub//要做的事情handler.postDelayed(this, 60000);send("定位成功 ");}};private void send(String message) {if(TextUtils.isEmpty(phone)) {ToastUtil.show(this,"您还没有设置手机号,请在侧滑菜单中设置手机号后重试!");return;}if (ContextCompat.checkSelfPermission(this,Manifest.permission.SEND_SMS)!= PackageManager.PERMISSION_GRANTED) {ToastUtil.show(this,"您没有获得发送短信的权限");}else{SmsManager smsManager = SmsManager.getDefault();Log.e("tag",""+currentLocation.length());smsManager.sendTextMessage(phone,"",message+currentLocation+"",null,null);ToastUtil.show(this,"发送位置成功");}}/***  启动应用的设置** @since 2.5.0**/private void startAppSettings() {Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);intent.setData(Uri.parse("package:" + getPackageName()));startActivity(intent);}private void initMap(Bundle savedInstanceState) {// 初始化地理围栏fenceClient = new GeoFenceClient(getApplicationContext());tvResult = (TextView)findViewById(R.id.tv_result);tvResult.setVisibility(View.GONE);showSetMapDialog = new Dialog(this);View view = LayoutInflater.from(this).inflate(R.layout.plugin_geofence_option, null);showSetMapDialog.setContentView(view);map_top = view.findViewById(R.id.map_top);lyOption = view.findViewById(R.id.ly_option);btAddFence = (Button) view.findViewById(R.id.bt_addFence);btOption = (Button) view.findViewById(R.id.bt_option);tvGuide = (TextView) view.findViewById(R.id.tv_guide);etRadius = (EditText) view.findViewById(R.id.et_radius);cbAlertIn = (CheckBox) view.findViewById(R.id.cb_alertIn);cbAlertOut = (CheckBox) view.findViewById(R.id.cb_alertOut);cbAldertStated = (CheckBox) view.findViewById(R.id.cb_alertStated);mMapView = (MapView) findViewById(R.id.map);mMapView.onCreate(savedInstanceState);markerOption = new MarkerOptions().draggable(true);init();String username = SpUtil.getString(ConstantValue.USER_LOGIN_INFO,"");List<User> users = DataSupport.where("username = ? ", username).find(User.class);if (users!=null && users.size()>0) {try{User user = users.get(0);phone = user.getSendMessagePhone();sendMessageDelay = Integer.parseInt(user.getSendMessageDelay());}catch (Exception e) {}}}private Dialog showSetMapDialog;private void showSetMapDialog() {if(showSetMapDialog.isShowing()) {showSetMapDialog.dismiss();}else {showSetMapDialog.show();}}@Overridepublic void onBackPressed() {DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);if (drawer.isDrawerOpen(GravityCompat.START)) {drawer.closeDrawer(GravityCompat.START);} else {super.onBackPressed();}}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.main, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {int id = item.getItemId();if (id == R.id.action_zhuxiao) {SpUtil.putInt(ConstantValue.USER_LOGIN_INFO,0);ToastUtil.show(this,"已注销当前帐号,请重新登录");startActivity(new Intent(this, LoginActivity.class));finish();return true;}if(id==R.id.action_exit) {finish();return true;}return super.onOptionsItemSelected(item);}@SuppressWarnings("StatementWithEmptyBody")@Overridepublic boolean onNavigationItemSelected(MenuItem item) {// Handle navigation view item clicks here.int id = item.getItemId();if (id == R.id.nav_phone) {showPhoneDialog();}else if(id == R.id.nav_weilan) {showSetMapDialog();}DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);drawer.closeDrawer(GravityCompat.START);return true;}private String phone;private void showPhoneDialog() {final EditText et = new EditText(this);et.setHint("11位手机号");if(!TextUtils.isEmpty(phone)) {et.setText(phone);}final EditText et1 = new EditText(this);et1.setHint("发送短信间隔(s)");et1.setInputType(InputType.TYPE_CLASS_NUMBER);LinearLayout linearLayout = new LinearLayout(this);linearLayout.addView(et);linearLayout.addView(et1);linearLayout.setOrientation(LinearLayout.VERTICAL);new AlertDialog.Builder(this).setTitle("请输入手机号和短信间隔").setView(linearLayout).setPositiveButton("确定", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which) {String input = et.getText().toString();if (input.equals("")) {Toast.makeText(getApplicationContext(), "手机号不能为空!" + input, Toast.LENGTH_LONG).show();}else {phone = input;String number = et1.getText().toString();try{int delay = Integer.parseInt(number);sendMessageDelay = delay * 1000;ToastUtil.show(MainActivity.this,"设置成功");String username = SpUtil.getString(ConstantValue.USER_LOGIN_INFO,"");List<User> users = DataSupport.where("username = ? ", username).find(User.class);if (users!=null && users.size()>0) {User user = users.get(0);user.setSendMessagePhone(phone);user.setSendMessageDelay(sendMessageDelay+"");user.update(user.getId());}}catch (Exception e) {ToastUtil.show(MainActivity.this,"请输入正确的数字");}}}}).setNegativeButton("取消", null).show();}void init() {if (mAMap == null) {mAMap = mMapView.getMap();mAMap.getUiSettings().setRotateGesturesEnabled(false);mAMap.moveCamera(CameraUpdateFactory.zoomBy(6));setUpMap();}btOption.setVisibility(View.VISIBLE);btOption.setText(getString(R.string.hideOption));resetView_round();btAddFence.setOnClickListener(this);btOption.setOnClickListener(this);cbAlertIn.setOnCheckedChangeListener(this);cbAlertOut.setOnCheckedChangeListener(this);cbAldertStated.setOnCheckedChangeListener(this);IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);filter.addAction(GEOFENCE_BROADCAST_ACTION);registerReceiver(mGeoFenceReceiver, filter);/*** 创建pendingIntent*/fenceClient.createPendingIntent(GEOFENCE_BROADCAST_ACTION);fenceClient.setGeoFenceListener(this);/*** 设置地理围栏的触发行为,默认为进入*/fenceClient.setActivateAction(GeoFenceClient.GEOFENCE_IN);}/*** 设置一些amap的属性*/private void setUpMap() {mAMap.setOnMapClickListener(this);mAMap.setLocationSource(this);// 设置定位监听mAMap.getUiSettings().setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示// 自定义系统定位蓝点MyLocationStyle myLocationStyle = new MyLocationStyle();// 自定义定位蓝点图标myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.drawable.gps_point));// 自定义精度范围的圆形边框颜色myLocationStyle.strokeColor(Color.argb(0, 0, 0, 0));// 自定义精度范围的圆形边框宽度myLocationStyle.strokeWidth(0);// 设置圆形的填充颜色myLocationStyle.radiusFillColor(Color.argb(0, 0, 0, 0));// 将自定义的 myLocationStyle 对象添加到地图上mAMap.setMyLocationStyle(myLocationStyle);mAMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false// 设置定位的类型为定位模式 ,可以由定位、跟随或地图根据面向方向旋转几种mAMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);}/*** 方法必须重写*/@Overrideprotected void onResume() {super.onResume();mMapView.onResume();}/*** 方法必须重写*/@Overrideprotected void onPause() {super.onPause();mMapView.onPause();}/*** 方法必须重写*/@Overrideprotected void onSaveInstanceState(Bundle outState) {super.onSaveInstanceState(outState);mMapView.onSaveInstanceState(outState);}/*** 方法必须重写*/@Overrideprotected void onDestroy() {super.onDestroy();mMapView.onDestroy();handler.removeCallbacks(runnable);handler.removeMessages(1);handler.removeMessages(2);handler.removeMessages(0);handler = null;try {unregisterReceiver(mGeoFenceReceiver);} catch (Throwable e) {}if (null != fenceClient) {fenceClient.removeGeoFence();}if (null != mlocationClient) {mlocationClient.onDestroy();}}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.bt_addFence :addFence();break;case R.id.bt_option :if (btOption.getText().toString().equals(getString(R.string.showOption))) {lyOption.setVisibility(View.VISIBLE);btOption.setText(getString(R.string.hideOption));} else {lyOption.setVisibility(View.GONE);btOption.setText(getString(R.string.showOption));}break;default :break;}}private void drawFence(GeoFence fence) {switch (fence.getType()) {case GeoFence.TYPE_ROUND :case GeoFence.TYPE_AMAPPOI :drawCircle(fence);break;case GeoFence.TYPE_POLYGON :case GeoFence.TYPE_DISTRICT :drawPolygon(fence);break;default :break;}removeMarkers();}private void drawCircle(GeoFence fence) {LatLng center = new LatLng(fence.getCenter().getLatitude(),fence.getCenter().getLongitude());// 绘制一个圆形mAMap.addCircle(new CircleOptions().center(center).radius(fence.getRadius()).strokeColor(Const.STROKE_COLOR).fillColor(Const.FILL_COLOR).strokeWidth(Const.STROKE_WIDTH));boundsBuilder.include(center);}private void drawPolygon(GeoFence fence) {final List<List<DPoint>> pointList = fence.getPointList();if (null == pointList || pointList.isEmpty()) {return;}for (List<DPoint> subList : pointList) {List<LatLng> lst = new ArrayList<LatLng>();PolygonOptions polygonOption = new PolygonOptions();for (DPoint point : subList) {lst.add(new LatLng(point.getLatitude(), point.getLongitude()));boundsBuilder.include(new LatLng(point.getLatitude(), point.getLongitude()));}polygonOption.addAll(lst);polygonOption.strokeColor(Const.STROKE_COLOR).fillColor(Const.FILL_COLOR).strokeWidth(Const.STROKE_WIDTH);mAMap.addPolygon(polygonOption);}}Object lock = new Object();void drawFence2Map() {new Thread() {@Overridepublic void run() {try {synchronized (lock) {if (null == fenceList || fenceList.isEmpty()) {return;}for (GeoFence fence : fenceList) {if (fenceMap.containsKey(fence.getFenceId())) {continue;}drawFence(fence);fenceMap.put(fence.getFenceId(), fence);}}} catch (Throwable e) {}}}.start();}Handler handler = new Handler() {public void handleMessage(Message msg) {switch (msg.what) {case 0 :StringBuffer sb = new StringBuffer();sb.append("添加围栏成功");Toast.makeText(getApplicationContext(), sb.toString(),Toast.LENGTH_SHORT).show();showSetMapDialog();drawFence2Map();break;case 1 :int errorCode = msg.arg1;Toast.makeText(getApplicationContext(),"添加围栏失败 " + errorCode, Toast.LENGTH_SHORT).show();break;case 2 :String statusStr = (String) msg.obj;tvResult.setVisibility(View.VISIBLE);tvResult.append(statusStr + "\n");break;default :break;}}};List<GeoFence> fenceList = new ArrayList<GeoFence>();@Overridepublic void onGeoFenceCreateFinished(final List<GeoFence> geoFenceList,int errorCode, String customId) {Message msg = Message.obtain();if (errorCode == GeoFence.ADDGEOFENCE_SUCCESS) {fenceList = geoFenceList;msg.obj = customId;msg.what = 0;} else {msg.arg1 = errorCode;msg.what = 1;}handler.sendMessage(msg);}/*** 接收触发围栏后的广播,当添加围栏成功之后,会立即对所有围栏状态进行一次侦测,如果当前状态与用户设置的触发行为相符将会立即触发一次围栏广播;* 只有当触发围栏之后才会收到广播,对于同一触发行为只会发送一次广播不会重复发送,除非位置和围栏的关系再次发生了改变。*/private BroadcastReceiver mGeoFenceReceiver = new BroadcastReceiver() {@Overridepublic void onReceive(Context context, Intent intent) {// 接收广播if (intent.getAction().equals(GEOFENCE_BROADCAST_ACTION)) {Bundle bundle = intent.getExtras();String customId = bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID);String fenceId = bundle.getString(GeoFence.BUNDLE_KEY_FENCEID);//status标识的是当前的围栏状态,不是围栏行为int status = bundle.getInt(GeoFence.BUNDLE_KEY_FENCESTATUS);StringBuffer sb = new StringBuffer();switch (status) {case GeoFence.STATUS_LOCFAIL :sb.append("定位失败");break;case GeoFence.STATUS_IN :sb.append("进入围栏 ");send("进入围栏 ");break;case GeoFence.STATUS_OUT :sb.append("离开围栏 ");send("离开围栏 ");break;case GeoFence.STATUS_STAYED :sb.append("停留在围栏内 ");break;default :break;}if(status != GeoFence.STATUS_LOCFAIL){if(!TextUtils.isEmpty(customId)){sb.append(" customId: " + customId);}sb.append(" fenceId: " + fenceId);}String str = sb.toString();Message msg = Message.obtain();msg.obj = str;msg.what = 2;handler.sendMessage(msg);}}};@Overridepublic void onMapClick(LatLng latLng) {markerOption.icon(ICON_YELLOW);centerLatLng = latLng;addCenterMarker(centerLatLng);tvGuide.setBackgroundColor(getResources().getColor(R.color.gary));tvGuide.setText("选中的坐标:" + centerLatLng.longitude + ","+ centerLatLng.latitude);}/*** 定位成功后回调函数*/private String currentLocation = " ";@Overridepublic void onLocationChanged(AMapLocation location) {if (mListener != null && location != null) {StringBuffer sb = new StringBuffer();//errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明if(location.getErrorCode() == 0){mListener.onLocationChanged(location);// 显示系统小蓝点sb.append("定位成功" + "\n");sb.append("经    度    : " + location.getLongitude() );sb.append("纬    度    : " + location.getLatitude() + "\n");sb.append("地    址    : " + location.getAddress() + "\n");} else {//定位失败sb.append("定位失败" + "\n");sb.append("错误码:" + location.getErrorCode() + "\n");sb.append("错误信息:" + location.getErrorInfo() + "\n");sb.append("错误描述:" + location.getLocationDetail() + "\n");}//解析定位结果,String result = sb.toString();currentLocation = "经度:"+location.getLatitude()+" 纬度:"+location.getLatitude()+" 位置:"+location.getAddress();tvResult.setText(result+"\n");currentLocation.replace("\n","");Log.e("tag","result: "+result);}}/*** 激活定位*/@Overridepublic void activate(OnLocationChangedListener listener) {mListener = listener;if (mlocationClient == null) {mlocationClient = new AMapLocationClient(this);mLocationOption =getDefaultOption();// 设置定位监听mlocationClient.setLocationListener(this);/*  // 设置为高精度定位模式mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);// 只是为了获取当前位置,所以设置为单次定位mLocationOption.setOnceLocation(false);*/// 设置定位参数mlocationClient.setLocationOption(mLocationOption);mlocationClient.startLocation();Log.e("tag","startlocation");}}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK) {Intent home = new Intent(Intent.ACTION_MAIN);home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);home.addCategory(Intent.CATEGORY_HOME);startActivity(home);return true;}return super.onKeyDown(keyCode, event);}private AMapLocationClientOption getDefaultOption(){AMapLocationClientOption mOption = new AMapLocationClientOption();mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式mOption.setGpsFirst(true);//可选,设置是否gps优先,只在高精度模式下有效。默认关闭mOption.setHttpTimeOut(30000);//可选,设置网络请求超时时间。默认为30秒。在仅设备模式下无效mOption.setInterval(5000);//可选,设置定位间隔。默认为2秒mOption.setNeedAddress(true);//可选,设置是否返回逆地理地址信息。默认是truemOption.setOnceLocation(false);//可选,设置是否单次定位。默认是falsemOption.setOnceLocationLatest(false);//可选,设置是否等待wifi刷新,默认为false.如果设置为true,会自动变为单次定位,持续定位时不要使用AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);//可选, 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTPmOption.setSensorEnable(false);//可选,设置是否使用传感器。默认是falsemOption.setWifiScan(true); //可选,设置是否开启wifi扫描。默认为true,如果设置为false会同时停止主动刷新,停止以后完全依赖于系统刷新,定位位置可能存在误差mOption.setLocationCacheEnable(true); //可选,设置是否使用缓存定位,默认为truereturn mOption;}/*** 停止定位*/@Overridepublic void deactivate() {mListener = null;if (mlocationClient != null) {mlocationClient.stopLocation();mlocationClient.onDestroy();}mlocationClient = null;}private void addCenterMarker(LatLng latlng) {if (null == centerMarker) {centerMarker = mAMap.addMarker(markerOption);}centerMarker.setPosition(latlng);markerList.add(centerMarker);}private void removeMarkers() {if(null != centerMarker){centerMarker.remove();centerMarker = null;}if (null != markerList && markerList.size() > 0) {for (Marker marker : markerList) {marker.remove();}markerList.clear();}}@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {switch (buttonView.getId()) {case R.id.cb_alertIn :if (isChecked) {activatesAction |= GeoFenceClient.GEOFENCE_IN;} else {activatesAction = activatesAction& (GeoFenceClient.GEOFENCE_OUT| GeoFenceClient.GEOFENCE_STAYED);}break;case R.id.cb_alertOut :if (isChecked) {activatesAction |= GeoFenceClient.GEOFENCE_OUT;} else {activatesAction = activatesAction& (GeoFenceClient.GEOFENCE_IN| GeoFenceClient.GEOFENCE_STAYED);}break;case R.id.cb_alertStated :if (isChecked) {activatesAction |= GeoFenceClient.GEOFENCE_STAYED;} else {activatesAction = activatesAction& (GeoFenceClient.GEOFENCE_IN| GeoFenceClient.GEOFENCE_OUT);}break;default :break;}if (null != fenceClient) {fenceClient.setActivateAction(activatesAction);}}private void resetView_round() {etRadius.setHint("围栏半径");etRadius.setVisibility(View.VISIBLE);tvGuide.setBackgroundColor(getResources().getColor(R.color.red));tvGuide.setText("请点击地图选择围栏的中心点");tvGuide.setVisibility(View.VISIBLE);}/*** 添加围栏** @since 3.2.0* @author hongming.wang**/private void addFence() {addRoundFence();}/*** 添加圆形围栏** @since 3.2.0* @author hongming.wang**/private void addRoundFence() {fenceClient.removeGeoFence();String radiusStr = etRadius.getText().toString();if (null == centerLatLng|| TextUtils.isEmpty(radiusStr)) {Toast.makeText(getApplicationContext(), "参数不全", Toast.LENGTH_SHORT).show();return;}DPoint centerPoint = new DPoint(centerLatLng.latitude,centerLatLng.longitude);fenceRadius = Float.parseFloat(radiusStr);fenceClient.addGeoFence(centerPoint, fenceRadius, "1");}
}

源码地址

Andoroid地理围栏定位与发送通知短信

注意

如果下载代码后运行地图没有显示,请在高德开放平台注册帐号并申请应用后替换项目中清单文件AndroidManifest.xml高德地图的key重新打包运行即可;

<meta-dataandroid:name="com.amap.api.v2.apikey"android:value="替换成自己申请的key" />

Android使用高德地图地理围栏定位自动发送短信相关推荐

  1. Android百度地图地理围栏定位间隔

    实现百度地图地理围栏定位间隔 继承GeoFenceClient,当定位成功的时候停止定位,间隔30秒再启动 public class MyGeoFenceClient extends GeoFence ...

  2. 设置电子围栏 高德地图_Java实现高德地图地理围栏设置功能工具类

    [Java] 纯文本查看 复制代码import com.alibaba.fastjson.JSONObject; import org.apache.http.client.methods.*; im ...

  3. php 开发高德地图地理围栏,地理围栏-辅助功能-开发指南-Android 定位SDK | 高德地图API...

    以下内容自定位 SDK V3.2.0 版本后支持. 第一步,创建地理围栏 地理围栏没有最大个数限制,您可以无限制的创建围栏.但请您根据业务需求合理的创建围栏,控制围栏个数可以有效的保证程序执行效率.定 ...

  4. 基于Android的谷歌地图地理围栏功能开发

    第一步.Android使用谷歌地图权限 Android上使用谷歌地图 必备条件:翻墙.Android设备上安装Google Play Service 由于谷歌在国内已经被墙了,所以我们只能使用翻墙软件 ...

  5. 关于高德地图地理围栏生成后在BroadcastReceiver的onReceive方法中没有接收到消息的问题

    昨天收到一个bug,说是地理围栏功能突然在部分手机上不能使用了,关键是好久没动过这块代码了(程序员的第一反映,这块代码好久没动过了,怎么会出错呢),我赶紧查找到相关代码进行查看发现没有报错,进一步调试 ...

  6. android使用高德地图SDK获取定位信息

    注册账号.创建应用.获取API KEY等这些就不说了,按照官网来就行,我们来讲讲项目的配置及示例代码. 高德地图获取定位信息配置要比百度地图简单多了,这是我比较喜欢的一点,而且之前用百度地图嵌入一个应 ...

  7. php 开发高德地图地理围栏,高德地图-地理围栏功能实现

    最近需要实现一个地理围栏相关的功能. 项目是和骑行相关的,主要是当游客或者骑友定位地址进入到对应的景点的地理围栏里面,则播报景点相关的报道语音. 接到需求之后,我开始查看高德的相关API,由于围栏是多 ...

  8. iOS 高德地图 地理围栏

    地理围栏是一个(或多个)圆形的地理边界作为虚拟围栏,当设备进入.离开该区域时,可以接收到消息通知. 地理围栏的半径数值需要大于0,如果 APP 退出,围栏随即失效. //使用说明//包含的头文件#im ...

  9. php 开发高德地图地理围栏,移动端地理围栏

    使用场景 可用于车辆的区域预警,人员区域监控,防止走失等场景. 用到产品 核心类/接口 核心难点 请求围栏: //请求围栏,并向围栏管理端添加 private void addFenceInAndSt ...

最新文章

  1. Selenium3自动化测试——15.调用Javascript进行滚动条控制
  2. [题解]洛谷P1119 灾后重建
  3. 在 Linux 下运行 ASP.NET 2.0
  4. TKStudio-LPC1220_GPIO_LED工程后记
  5. SIFT特征提取分析
  6. m函数与m文件的命名
  7. VisualNet在资源管理中的应用
  8. 【大数据部落】用关联规则和聚类探索药物配伍规律
  9. Mysql 计划任务
  10. kettle将excel导入数据库_Kettle从excel导入数据到sql server
  11. c语言编译器不支持c99,Visual Studio2013的C语言编译器对C99标准的支持情况
  12. 解决weka打开不了package manner的方法!
  13. C语言大一上学期总结
  14. vue笔记——本地应用
  15. db mysql error_list
  16. 正在解析主机 失败:未知的名称或服务。 wget: 无法解析主机地址
  17. JAVA设计模式理解与总结(下)代理模式适配器模式观察者模式
  18. 计算机病毒教学评课,计算机病毒评课稿.doc
  19. 数据库DB与数据仓库DW区别和联系
  20. TOM-610重锤式电阻测试仪-表面电阻测试利器

热门文章

  1. 如何有效提升技术[成为大Niu]的两个方法
  2. python 不区分大小写的字典实现
  3. 【新手入门必看】MaixPy 图像基础知识
  4. 细说API - 认证、授权和凭证
  5. 使用HybridSN进行高光谱图像分类
  6. 支付宝推“移动花卡”:花呗账单延后还
  7. matlab人脸识别开题报告,基于人脸识别的出勤点名系统中特征提取算法研究开题报告...
  8. STM32通过IIC读取BH1750光照数据
  9. DOS窗口下使用命令打开远程桌面连接
  10. 学习servlet【续】