com.amap.api.location.AMapLocationListener Java Examples
The following examples show how to use
com.amap.api.location.AMapLocationListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AMapRxLocationManager.java From RxLocation with Apache License 2.0 | 5 votes |
@Override public void call(final Subscriber<? super AMapLocation> subscriber) { mListener = new AMapLocationListener() { @Override public void onLocationChanged(final AMapLocation aMapLocation) { subscriber.onNext(aMapLocation); } }; mAMapLocationClient.setLocationListener(mListener); synchronized (RxLocationListener.class) { mAMapLocationClient.startLocation(); } subscriber.add(new Subscription() { @Override public void unsubscribe() { if (!subscriber.isUnsubscribed()) { subscriber.unsubscribe(); } removeListener(); } @Override public boolean isUnsubscribed() { return subscriber.isUnsubscribed(); } }); }
Example #2
Source File: InitHelper.java From AndroidAll with Apache License 2.0 | 5 votes |
public static void initAMap(Context context) { AMapLocationClient mLocationClient = new AMapLocationClient(context.getApplicationContext()); mLocationClient.setLocationListener(new AMapLocationListener() { @Override public void onLocationChanged(AMapLocation aMapLocation) { // 一些处理 } }); AMapLocationClientOption mLocationOption = new AMapLocationClientOption(); mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); mLocationOption.setOnceLocation(true); mLocationClient.setLocationOption(mLocationOption); mLocationClient.startLocation(); }
Example #3
Source File: AMapLocationListenerProxy.java From DoraemonKit with Apache License 2.0 | 4 votes |
public AMapLocationListenerProxy(AMapLocationListener aMapLocationListener) { this.aMapLocationListener = aMapLocationListener; }
Example #4
Source File: GeoFence_Old_Activity.java From Android_Location_Demo with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_geofence_old); setTitle(R.string.oldGeoFence); etRadius = (EditText) findViewById(R.id.et_radius); cbAlertIn = (CheckBox) findViewById(R.id.cb_alertIn); cbAlertOut = (CheckBox) findViewById(R.id.cb_alertOut); tvReult = (TextView) findViewById(R.id.tv_result); btFence = (Button) findViewById(R.id.bt_fence); btFence.setOnClickListener(this); IntentFilter fliter = new IntentFilter( ConnectivityManager.CONNECTIVITY_ACTION); fliter.addAction(GEOFENCE_BROADCAST_ACTION); registerReceiver(mGeoFenceReceiver, fliter); Intent intent = new Intent(GEOFENCE_BROADCAST_ACTION); mPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0); onceClient = new AMapLocationClient(getApplicationContext()); locationClient = new AMapLocationClient(this.getApplicationContext()); locationOption = new AMapLocationClientOption(); // 设置定位模式高精度,添加地理围栏最好设置成高精度模式 locationOption.setLocationMode(AMapLocationMode.Hight_Accuracy); // 设置定位监听 locationClient.setLocationListener(this); AMapLocationClientOption onceOption = new AMapLocationClientOption(); onceOption.setOnceLocation(true); onceClient.setLocationOption(onceOption); onceClient.setLocationListener(new AMapLocationListener() { @Override public void onLocationChanged(AMapLocation loc) { if (loc != null) { if (loc.getErrorCode() == 0) { if (null != locationClient) { float radius = 1000; String strRadius = etRadius.getText().toString(); if (!TextUtils.isEmpty(strRadius)) { radius = Float.valueOf(strRadius); } // 添加地理围栏, // 第一个参数:围栏ID,可以自定义ID,示例中为了方便只使用一个ID;第二个:纬度;第三个:精度; // 第四个:半径;第五个:过期时间,单位毫秒,-1代表不过期;第六个:接收触发消息的PendingIntent locationClient.addGeoFenceAlert("fenceId", loc.getLatitude(), loc.getLongitude(), radius, -1, mPendingIntent); } } else { Toast.makeText(getApplicationContext(), "获取当前位置失败!", Toast.LENGTH_SHORT).show(); Message msg = mHandler.obtainMessage(); msg.obj = loc; msg.what = -1; mHandler.sendMessage(msg); } } } }); }
Example #5
Source File: GeoFence_Old_Activity.java From Android_Location_Demo with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_geofence_old); setTitle(R.string.oldGeoFence); etRadius = (EditText) findViewById(R.id.et_radius); cbAlertIn = (CheckBox) findViewById(R.id.cb_alertIn); cbAlertOut = (CheckBox) findViewById(R.id.cb_alertOut); tvReult = (TextView) findViewById(R.id.tv_result); btFence = (Button) findViewById(R.id.bt_fence); btFence.setOnClickListener(this); IntentFilter fliter = new IntentFilter( ConnectivityManager.CONNECTIVITY_ACTION); fliter.addAction(GEOFENCE_BROADCAST_ACTION); registerReceiver(mGeoFenceReceiver, fliter); Intent intent = new Intent(GEOFENCE_BROADCAST_ACTION); mPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0); onceClient = new AMapLocationClient(getApplicationContext()); locationClient = new AMapLocationClient(this.getApplicationContext()); locationOption = new AMapLocationClientOption(); // 设置定位模式高精度,添加地理围栏最好设置成高精度模式 locationOption.setLocationMode(AMapLocationMode.Hight_Accuracy); // 设置定位监听 locationClient.setLocationListener(this); AMapLocationClientOption onceOption = new AMapLocationClientOption(); onceOption.setOnceLocation(true); onceClient.setLocationOption(onceOption); onceClient.setLocationListener(new AMapLocationListener() { @Override public void onLocationChanged(AMapLocation loc) { if (loc != null) { if (loc.getErrorCode() == 0) { if (null != locationClient) { float radius = 1000; String strRadius = etRadius.getText().toString(); if (!TextUtils.isEmpty(strRadius)) { radius = Float.valueOf(strRadius); } // 添加地理围栏, // 第一个参数:围栏ID,可以自定义ID,示例中为了方便只使用一个ID;第二个:纬度;第三个:精度; // 第四个:半径;第五个:过期时间,单位毫秒,-1代表不过期;第六个:接收触发消息的PendingIntent locationClient.addGeoFenceAlert("fenceId", loc.getLatitude(), loc.getLongitude(), radius, -1, mPendingIntent); } } else { Toast.makeText(getApplicationContext(), "获取当前位置失败!", Toast.LENGTH_SHORT).show(); Message msg = mHandler.obtainMessage(); msg.obj = loc; msg.what = -1; mHandler.sendMessage(msg); } } } }); }