本文整理匯總了Java中com.baidu.location.BDLocationListener類的典型用法代碼示例。如果您正苦於以下問題:Java BDLocationListener類的具體用法?Java BDLocationListener怎麽用?Java BDLocationListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BDLocationListener類屬於com.baidu.location包,在下文中一共展示了BDLocationListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: call
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
@Override
public void call(final Subscriber<? super BDLocation> subscriber) {
BDLocation lateKnownLocation = LocationClient.get(context).getLastKnownLocation();
if (lateKnownLocation != null) {
subscriber.onNext(lateKnownLocation);
subscriber.onCompleted();
} else {
BDLocationListener bdLocationListener = new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation bdLocation) {
subscriber.onNext(bdLocation);
subscriber.onCompleted();
}
};
LocationClient.get(context).locate(bdLocationListener);
}
}
示例2: getCity
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
private void getCity() {
mListener = new BDLocationListener(){
@Override
public void onReceiveLocation(BDLocation location) {
if (null != location && location.getLocType() != BDLocation.TypeServerError){
city=location.getCity();
location_city.setText(location.getCity());
addess=location.getAddrStr();
Lat=location.getLatitude();
Lng=location.getLongitude();
Log.e("Address", addess);
Log.e("CCCC",city);
getDate();
}
}
};
}
示例3: Getctiy
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
public static String Getctiy(){
mListener = new BDLocationListener(){
@Override
public void onReceiveLocation(BDLocation location) {
if (null != location && location.getLocType() != BDLocation.TypeServerError){
city=location.getCity();
// location_city.setText(location.getCity());
// addess=location.getAddrStr();
// Lat=location.getLatitude();
// Lng=location.getLongitude();
// Log.e("Address", addess);
Log.e("CCCC",city);
}
}
};
return city;
}
示例4: onCreate
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
@Override
public void onCreate(Context context) {
mLocationClient = new LocationClient(context);
mLocationClient.registerLocationListener(new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation bdLocation) {
mLatitude = bdLocation.getLatitude();
mLontitude = bdLocation.getLongitude();
}
});
LocationClientOption option = new LocationClientOption();
option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);//可選,默認高精度,設置定位模式,高精度,低功耗,僅設備
option.setCoorType("gcj02");//可選,默認gcj02,設置返回的定位結果坐標係,
int span = 2000;
option.setScanSpan(span);//可選,默認0,即僅定位一次,設置發起定位請求的間隔需要大於等於1000ms才是有效的
// option.setIsNeedAddress(checkGeoLocation.isChecked());//可選,設置是否需要地址信息,默認不需要
option.setOpenGps(true);//可選,默認false,設置是否使用gps
option.setLocationNotify(true);//可選,默認false,設置是否當gps有效時按照1S1次頻率輸出GPS結果
option.setIgnoreKillProcess(false);//可選,默認true,定位SDK內部是一個SERVICE,並放到了獨立進程,設置是否在stop的時候殺死這個進程,默認不殺死
option.setEnableSimulateGps(false);//可選,默認false,設置是否需要過濾gps仿真結果,默認需要
mLocationClient.setLocOption(option);
mLocationClient.start();
bindService(context);
}
示例5: getLocation
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
private String getLocation() {
mLocationClient = new LocationClient(mContext);
mLocationClient.registerLocationListener(new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation bdLocation) {
mLocation = bdLocation.getAddress().address;
mUserDetailFragView.updateLocation(mLocation);
mLocationClient.stop();
}
});
LocationClientOption option = new LocationClientOption();
option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);//可選,默認高精度,設置定位模式,高精度,低功耗,僅設備
option.setCoorType("gcj02");//可選,默認gcj02,設置返回的定位結果坐標係,
int span = 2000;
option.setScanSpan(span);//可選,默認0,即僅定位一次,設置發起定位請求的間隔需要大於等於1000ms才是有效的
option.setIsNeedAddress(true);//可選,設置是否需要地址信息,默認不需要
option.setOpenGps(true);//可選,默認false,設置是否使用gps
option.setLocationNotify(true);//可選,默認false,設置是否當gps有效時按照1S1次頻率輸出GPS結果
option.setIgnoreKillProcess(false);//可選,默認true,定位SDK內部是一個SERVICE,並放到了獨立進程,設置是否在stop的時候殺死這個進程,默認不殺死
option.setEnableSimulateGps(false);//可選,默認false,設置是否需要過濾gps仿真結果,默認需要
mLocationClient.setLocOption(option);
mLocationClient.start();
return mLocation;
}
示例6: initData
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
@Override
public void initData() {
ButterKnife.bind(this);
FragmentManager fm = getSupportFragmentManager();
HomeFragment homeFragment = (HomeFragment) fm.findFragmentById(R.id.fragment_container);
if (homeFragment == null) {
homeFragment = HomeFragment.newInstance();
fm.beginTransaction().add(R.id.fragment_container,homeFragment).commit();
}
mHomePresenter = new HomePresenter(homeFragment);
BDLocationListener myListener = new MyLocationListener();
MyApplication.getmLocationClient().registerLocationListener(myListener);
//
}
示例7: onCreate
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 設置程序標題
setTitle(R.string.app_title);
// 設置內容
setContentView(R.layout.activity_main);
// umeng統計
MobclickAgent.updateOnlineConfig(getApplication());
// 接收用戶選擇的城市屬性
CityModel city = getIntent().getParcelableExtra("select_city");
if (city == null) {
// 定位用戶地理位置
((MyApplication) getApplication()).registerLocationListener(BDLocationListener);
((MyApplication) getApplication()).LocationStart();
} else {
showMainActivity(city);
}
}
示例8: onReceiveLocation
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
@Override
public void onReceiveLocation(BDLocation location) {
if (location == null)
return;
switch (location.getLocType()) {
// 定位成功
case BDLocation.TypeGpsLocation:
case BDLocation.TypeNetWorkLocation:
case BDLocation.TypeOffLineLocation:
showMainActivity(Integer.valueOf(location.getCityCode()));
((MyApplication) getApplication()).LocationStop();
((MyApplication) getApplication()).unRegisterLocationListener(BDLocationListener);
break;
// 定位失敗
default:
break;
}
}
示例9: watchPosition
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
private boolean watchPosition(JSONObject options, int watchId, final CallbackContext callback) {
Log.i(TAG, "監聽位置變化");
Context ctx = cordova.getActivity().getApplicationContext();
PositionOptions positionOpts = new PositionOptions(options);
BDGeolocation geolocation = new BDGeolocation(ctx);
store.put(watchId, geolocation);
return geolocation.watchPosition(positionOpts, new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation location) {
JSONArray message = new MessageBuilder(location).build();
PluginResult result = new PluginResult(PluginResult.Status.OK, message);
result.setKeepCallback(true);
callback.sendPluginResult(result);
}
});
}
示例10: registerListener
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
/***
*
* @param listener
* @return
*/
public boolean registerListener(BDLocationListener listener){
boolean isSuccess = false;
if(listener != null){
client.registerLocationListener(listener);
isSuccess = true;
}
return isSuccess;
}
示例11: locate
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
public void locate(final BDLocationListener bdLocationListener) {
final BDLocationListener realListener = new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation bdLocation) {
bdLocationListener.onReceiveLocation(bdLocation);
//防止內存溢出
realClient.unRegisterLocationListener(this);
stop();
}
};
realClient.registerLocationListener(realListener);
if (!realClient.isStarted()) {
realClient.start();
}
}
示例12: call
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
@Override
public void call(final Subscriber<? super BDLocation> subscriber) {
BDLocationListener bdLocationListener = new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation bdLocation) {
subscriber.onNext(bdLocation);
subscriber.onCompleted();
}
};
LocationClient.get(context).locate(bdLocationListener);
}
示例13: registerListener
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
/***
*
* @param listener
* @return
*/
public boolean registerListener(BDLocationListener listener){
boolean isSuccess = false;
if(listener != null){
client.registerLocationListener(listener);
isSuccess = true;
}
return isSuccess;
}
示例14: registerLocationListener
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
public boolean registerLocationListener(BDLocationListener listener){
boolean isSuccess = false;
if(listener != null){
mClient.registerLocationListener(listener);
isSuccess = true;
}
return isSuccess;
}
示例15: requestLocation
import com.baidu.location.BDLocationListener; //導入依賴的package包/類
public void requestLocation(final LocationResultListener listener, final int retry) {
locationClient.start();
locationClient.registerLocationListener(new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation bdLocation) {
locationClient.unRegisterLocationListener(this);
String city = bdLocation.getCity();
boolean success = true;
if (TextUtils.isEmpty(city)) {
city = null;
success = false;
if (retry < 3) {
Log.e("LocationProvider", "request location failure retry " + retry + " times");
requestLocation(listener, retry + 1);
return;
}
} else {
// 大多數情況下,將"廣州市"直接顯示成"廣州"
city = city.replaceFirst("市.*$", "");
}
locationClient.stop();
listener.onLocationResult(success, city, bdLocation.getCity() + bdLocation.getDistrict(), bdLocation.getLatitude(), bdLocation.getLongitude());
}
});
// 0:正常發起了定位。
// 1:服務沒有啟動。
// 2:沒有監聽函數。
// 6:請求間隔過短。 前後兩次請求定位時間間隔不能小於1000ms。
int code = locationClient.requestLocation();
if (code == 6) {
locationClient.requestOfflineLocation();
}
}