com.baidu.location.BDLocation Java Examples

The following examples show how to use com.baidu.location.BDLocation. 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: MainActivity.java    From nearbydemo with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
	//Receive Location 
	StringBuffer sb = new StringBuffer(256);
	sb.append("\nlatitude : ");
	sb.append(location.getLatitude());
	sb.append("\nlontitude : ");
	sb.append(location.getLongitude());
	Log.d(TAG, "Latitude: " + location.getLatitude());
	Log.d(TAG, "location: " + location.getLongitude());
	Map<String, String> map = new HashMap<String, String>();
	map.put("latitude", String.valueOf(location.getLatitude()));
	map.put("longitude", String.valueOf(location.getLongitude()));
	map.put("user_id", PhoneUtil.getImei(MainActivity.this));
	requestServer(map);
	Log.i(TAG, sb.toString());
}
 
Example #2
Source File: LocationUtils.java    From WayHoo with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
	if (location == null || location.getLocType() != 161
			|| TextUtils.isEmpty(location.getCity())) {
		mTryCount++;
		if (mTryCount >= MAX_TRY_COUNT) {
			mListener.failed();
			stopLocation();
		}
		return;
	}

	String city = location.getCity().replace("市", "");
	mListener.succeed(city);
	stopLocation();// 停止定位
}
 
Example #3
Source File: WelcomeActivity.java    From CoolWeather with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
	if (location != null) {
		normalDistrict = location.getDistrict();
		locationCity = location.getCity();
		
		if(locationCity == null){
			Toast.makeText(WelcomeActivity.this, "定位失败,请检查网络", Toast.LENGTH_SHORT).show();
		}else{
			String[] str = locationCity.split("市");
			locationCity = str[0];
			if("".equals(locationCity)){
				Toast.makeText(WelcomeActivity.this, "定位失败,默认为武汉", Toast.LENGTH_LONG).show();
			}
		}
	}
}
 
Example #4
Source File: GeolocationPlugin.java    From cordova-plugin-baidu-geolocation with MIT License 6 votes vote down vote up
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);
    }
  });
}
 
Example #5
Source File: WeatherService.java    From Dainty with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation bdLocation) {
    if (bdLocation.getLocType() == 63)
        Toast.makeText(WeatherService.this, "请检查网络", Toast.LENGTH_SHORT).show();
    else {
        city = bdLocation.getDistrict();   //具体到区县的定位
        SharedPreferences.Editor pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
        pref.putString("cityName", city);
        pref.apply();

        if (city != null) {
            presenter.getWeatherInfo(city);
        }

    }
    WeatherService.this.stopSelf();
}
 
Example #6
Source File: WeatherActivity.java    From FoodOrdering with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation bdLocation) {
    Log.d("location****", bdLocation.getCity() + bdLocation.getDistrict());
    String areaName = TextUtil.getFormatArea(bdLocation.getDistrict());
    String cityName = TextUtil.getFormatArea(bdLocation.getCity());
    City city = cityDao.getCityByCityAndArea(cityName, areaName);
    if (city == null) {
        city = cityDao.getCityByCityAndArea(cityName, cityName);
        if (city == null) {
            swipeRefreshLayout.post(new Runnable() {
                @Override
                public void run() {
                    swipeRefreshLayout.setRefreshing(false);
                }
            });
            return;
        }
    }
    weatherManager.insertNewUseArea(city, true);
    weatherID = city.getWeatherId();
    mCurrentAreaTv.setText(city.getAreaName());
    refresh(true);
}
 
Example #7
Source File: WBNearbyActivity.java    From Simpler with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
    // 在回调方法运行在remote进程
    // 获取定位类型
    int locType = location.getLocType();
    if (locType == BDLocation.TypeGpsLocation || locType == BDLocation.TypeNetWorkLocation
            || locType == BDLocation.TypeOffLineLocation) {
        // 定位成功。GPS定位结果 || 网络定位结果 || 离线定位结果
        // 纬度
        mLatitude = String.valueOf(location.getLatitude());
        // 经度
        mLongitude = String.valueOf(location.getLongitude());
        mHandler.sendEmptyMessage(HANDLE_ADDRESS_OK);
    } else if (location.getLocType() == BDLocation.TypeServerError) {
        mHandler.sendEmptyMessage(HANDLE_SERVER_ERROR);
    } else if (location.getLocType() == BDLocation.TypeNetWorkException) {
        mHandler.sendEmptyMessage(HANDLE_NETWORK_EXCEPTION);
    } else if (location.getLocType() == BDLocation.TypeCriteriaException) {
        mHandler.sendEmptyMessage(HANDLE_CRITERIA_EXCEPTION);
    }
}
 
Example #8
Source File: Activity_Location.java    From FoodOrdering with Apache License 2.0 6 votes vote down vote up
private void navigateTo(BDLocation location) {
    longitude = location.getLongitude();
    latitude = location.getLatitude();
    tv_longitude.setText(longitude + "");
    tv_latitude.setText(latitude + "");
    address = location.getAddrStr();
    tv_address.setText(address);
    if (isFirstLocation) {
        latLng = new LatLng(latitude, longitude);
        MapStatus.Builder builder = new MapStatus.Builder();
        MapStatus mapStatus = builder.target(latLng).zoom(15.0f).build();
        mBaiduMap.animateMapStatus(MapStatusUpdateFactory
                .newMapStatus(mapStatus));
        isFirstLocation = false;
    }
    MyLocationData.Builder locationBuilder = new MyLocationData.Builder();
    locationBuilder.latitude(location.getLatitude());
    locationBuilder.longitude(location.getLongitude());
    MyLocationData locationData = locationBuilder.build();
    mBaiduMap.setMyLocationData(locationData);
}
 
Example #9
Source File: WBPostActivity.java    From Simpler with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
    // 在回调方法运行在remote进程
    // 获取定位类型
    int locType = location.getLocType();
    if (locType == BDLocation.TypeGpsLocation || locType == BDLocation.TypeNetWorkLocation
            || locType == BDLocation.TypeOffLineLocation) {
        // 定位成功。GPS定位结果 || 网络定位结果 || 离线定位结果
        // 纬度
        mLatitude = location.getLatitude();
        // 经度
        mLongitude = location.getLongitude();
        // 获取地址信息
        mAddrStr = location.getAddrStr();
        mHandler.sendEmptyMessage(HANDLE_ADDRESS_OK);
    } else if (location.getLocType() == BDLocation.TypeServerError) {
        mHandler.sendEmptyMessage(HANDLE_SERVER_ERROR);
    } else if (location.getLocType() == BDLocation.TypeNetWorkException) {
        mHandler.sendEmptyMessage(HANDLE_NETWORK_EXCEPTION);
    } else if (location.getLocType() == BDLocation.TypeCriteriaException) {
        mHandler.sendEmptyMessage(HANDLE_CRITERIA_EXCEPTION);
    }
}
 
Example #10
Source File: ShareLocationActivity.java    From imsdk-android with MIT License 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation bdLocation) {
    MyLocationData data;
    MyLocationData.Builder builder = new MyLocationData.Builder();
    if (baiduMap != null) {
        data = builder.direction(bdLocation.getDirection())
                .latitude(bdLocation.getLatitude())
                .longitude(bdLocation.getLongitude())
                .direction(bdLocation.getDirection())
                .build();
        baiduMap.setMyLocationData(data);
        addOverLay(myId,new LatLng(bdLocation.getLatitude(),bdLocation.getLongitude()),bdLocation.getDirection());

        ShareLocationData locationData = new ShareLocationData();
        locationData.direction = Double.toString( bdLocation.getDirection());
        locationData.latitude = Double.toString(bdLocation.getLatitude());
        locationData.longitude = Double.toString(bdLocation.getLongitude());
        if (!inited){
            //第一次收到消息自动缩放地图
            inited = true;
            zoomMap();
        }
        presenter.sendLocationData(locationData);
    }
}
 
Example #11
Source File: SearchGoodsActivity.java    From school_shop with MIT License 6 votes vote down vote up
@Override
		public void onReceiveLocation(BDLocation location) {
			//Receive Location 
			lat = location.getLatitude();
			lont = location.getLongitude();
//			showButtomToast("lat="+location.getLatitude()+" , lont="+location.getLocType());
			//定位成功
			if (location.getLocType()==161||location.getLocType()==61) {
				isLocalSuccess = localsuccess;
				mLocationClient.stop();
				progressBarTitle.setText(getStringByRId(R.string.localSuccess));
				showButtomToast(getStringByRId(R.string.localSuccess));
			}else if (location.getLocType()==167||location.getLocType()==62) {
				isLocalSuccess = localfail;
				showButtomToast(getStringByRId(R.string.localFail));
				mLocationClient.stop();
			}
		}
 
Example #12
Source File: BaiduUtils.java    From LocationProvider with Apache License 2.0 6 votes vote down vote up
/**
 * 判断位置是否可用
 *
 * @param bdLocation
 * @return
 */
public static final boolean isValidLocation(BDLocation bdLocation, BDLocation cashLocation) {
    boolean isValid = false;
    if (bdLocation.getLocType() == BDLocation.TypeGpsLocation) {
        // 当前为GPS定位结果
        isValid = true;
    } else if (bdLocation.getLocType() == BDLocation.TypeNetWorkLocation) {
        // 当前为网络定位结果
        if (cashLocation == null || !cashLocation.getTime().equals(bdLocation.getTime()))
            isValid = true;
    } else if (bdLocation.getLocType() == BDLocation.TypeOffLineLocation) {
        // 当前为离线定位结果
    } else if (bdLocation.getLocType() == BDLocation.TypeServerError) {
        // 当前网络定位失败
        // 可将定位唯一ID、IMEI、定位失败时间反馈至[email protected]
    } else if (bdLocation.getLocType() == BDLocation.TypeNetWorkException) {
        // 当前网络不通
    } else if (bdLocation.getLocType() == BDLocation.TypeCriteriaException) {
        // 当前缺少定位依据,可能是用户没有授权,建议弹出提示框让用户开启权限
        // 可进一步参考onLocDiagnosticMessage中的错误返回码
    }

    return isValid;
}
 
Example #13
Source File: MainActivity.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation bdLocation) {
    //查看定位结果
    Log.d("Tag", "定位返回----" + bdLocation.getAddrStr());

    //定位成功后,把定位的点,设置地图的中心点
    //包装经纬,从定位信息中,获取经纬度
    LatLng currentLatLng = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude());

    //构建地图状态
    MapStatus status = new MapStatus.Builder()
            //包装经纬度
            .target(currentLatLng)
            //缩放等级
            .zoom(15)
            //构建
            .build();
    //通过地图工厂设置地图状态
    MapStatusUpdate update = MapStatusUpdateFactory.newMapStatus(status);
    //更新地图界面
    mBaiduMap.setMapStatus(update);

}
 
Example #14
Source File: LocationService.java    From Conquer with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
    L.i(location.getLocType() + "," + +location.getOperators() + "," + location.getLatitude() + ","
            + location.getLongitude() + "," + location.getAddrStr());
    // 成功定位
    if (location.getLocType() == 161 || location.getLocType() == 61) {
        lastPoint = new LocationInfo(location.getLongitude(), location.getLatitude(),
                location.getAddrStr());
    } else {// 定位失败
        lastPoint = new LocationInfo(0, 0, "定位失败");
    }
    // 停止定位
    mLocationClient.stop();
    if (listener != null) {
        listener.onLocateCompleted(lastPoint);
    }
}
 
Example #15
Source File: LocationLastKnownOnSubscribe.java    From FakeWeather with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #16
Source File: MainActivity.java    From BaiDuMapSelectDemo with Apache License 2.0 6 votes vote down vote up
/**
 * 根据获取到的位置在地图上移动“我”的位置
 *
 * @param location
 */
private void navigateTo(BDLocation location) {
    double longitude = location.getLongitude();
    double latitude = location.getLatitude();
    String address = location.getAddrStr();
    if (isFirstLocation) {
        currentLatLng = new LatLng(latitude, longitude);
        MapStatus.Builder builder = new MapStatus.Builder();
        MapStatus mapStatus = builder.target(currentLatLng).zoom(17.0f).build();
        mBaiduMap.animateMapStatus(MapStatusUpdateFactory
                .newMapStatus(mapStatus));
        isFirstLocation = false;

        //反向地理解析(含有poi列表)
        mGeoCoder.reverseGeoCode(new ReverseGeoCodeOption()
                .location(currentLatLng));
    }
    MyLocationData.Builder locationBuilder = new MyLocationData.Builder();
    locationBuilder.latitude(location.getLatitude());
    locationBuilder.longitude(location.getLongitude());
    MyLocationData locationData = locationBuilder.build();
    mBaiduMap.setMyLocationData(locationData);
}
 
Example #17
Source File: LocationUtil.java    From AndroidDemo with MIT License 6 votes vote down vote up
public LocationUtil(Context context) {
    locationClient = new LocationClient(context);
    locationClient.setLocOption(getOption());
    locationClient.registerLocationListener(locationListener = new LocationListener() {
        @Override
        public void onReceiveLocation(BDLocation bdLocation) {
            if (bdListener != null) {
                locationClient.stop();
                bdListener.onReceiveLocation(bdLocation);
            }
        }

        @Override
        public void onLocDiagnosticMessage(int i, int i1, String s) {
            if (bdListener != null) {
                bdListener.onFail(i, s);
            }
        }
    });
}
 
Example #18
Source File: LocationDelegate.java    From FastWaiMai with MIT License 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
	if (location == null){
		return;
	}

	if (location.getLocType() == BDLocation.TypeGpsLocation
			|| location.getLocType() == BDLocation.TypeNetWorkLocation) {

		currentAddr = location.getAddrStr();
		//当前所在位置
		LatLng currentLatLng = new LatLng(location.getLatitude(), location.getLongitude());
		mGeoCoder.reverseGeoCode(new ReverseGeoCodeOption()
				.location(currentLatLng)
				.radius(radius));

	}

}
 
Example #19
Source File: AddressEditDelegate.java    From FastWaiMai with MIT License 6 votes vote down vote up
/**
 * 根据获取到的位置在地图上移动"我"的位置
 *
 * @param location
 */
private void navigateTo(BDLocation location) {
	double longitude = location.getLongitude();
	double latitude = location.getLatitude();
	String address = location.getAddrStr();
	if (isFirstLocation) {
		currentLatLng = new LatLng(latitude, longitude);
		MapStatus.Builder builder = new MapStatus.Builder();
		MapStatus mapStatus = builder.target(currentLatLng).zoom(17.0f).build();
		mBaiduMap.animateMapStatus(MapStatusUpdateFactory
				.newMapStatus(mapStatus));
		isFirstLocation = false;

		//反向地理解析(含有poi列表)
		mGeoCoder.reverseGeoCode(new ReverseGeoCodeOption()
				.location(currentLatLng)
				.radius(radius));
	}
	MyLocationData.Builder locationBuilder = new MyLocationData.Builder();
	locationBuilder.latitude(location.getLatitude());
	locationBuilder.longitude(location.getLongitude());
	MyLocationData locationData = locationBuilder.build();
	mBaiduMap.setMyLocationData(locationData);
}
 
Example #20
Source File: AddressEditDelegate.java    From FastWaiMai with MIT License 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
	if (location == null || mMapView == null) {
		return;
	}

	Log.e(TAG, "当前“我”的位置:" + location.getAddrStr());
	if (location.getLocType() == BDLocation.TypeGpsLocation
			|| location.getLocType() == BDLocation.TypeNetWorkLocation) {
		navigateTo(location);
		cityName = location.getCity();
		mTvCurrrentCity.setText(cityName);
		Log.e(TAG, "当前定位城市:" + location.getCity() +
				"定位地址: " + location.getAddress());
	}

}
 
Example #21
Source File: InvitationCategoryAdapter.java    From PlayTogether with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location)
{
	if (location.getLocType() == BDLocation.TypeGpsLocation || location
					.getLocType() == BDLocation.TypeNetWorkLocation || location
					.getLocType() == BDLocation.TypeOffLineLocation)
	{
		mTv.setText(location.getAddrStr());
		//将经纬度保存到服务器
		EventBus.getDefault().post(new EventLocate(location.getLatitude(),
						location.getLongitude()));
	} else
	{
		Toast.makeText(mContext, "定位失败,检查网络是否通畅", Toast.LENGTH_SHORT).show();
	}
	LocationUtils.stopClient();
}
 
Example #22
Source File: BaiduUtils.java    From LocationProvider with Apache License 2.0 5 votes vote down vote up
public static void prinftBDLocation(BDLocation bdLocation) {
    Log.d("@@@", "====================BDLocation Strat====================");
    String str = "BDLocation{" + "locationID='" + bdLocation.getLocationID() + '\'' +
            ", locType=" + bdLocation.getLocType() +
            ", locTime='" + bdLocation.getTime() + '\'' +
            ", latitude=" + bdLocation.getLatitude() +
            ", longitude=" + bdLocation.getLongitude() +
            ", radius=" + bdLocation.getRadius() +
            ", addrStr=" + bdLocation.getAddrStr() +
            ", country='" + bdLocation.getCountry() + '\'' +
            ", countryCode='" + bdLocation.getCountryCode() + '\'' +
            ", city='" + bdLocation.getCity() + '\'' +
            ", cityCode='" + bdLocation.getCityCode() + '\'' +
            ", district='" + bdLocation.getDistrict() + '\'' +
            ", street='" + bdLocation.getStreet() + '\'' +
            ", streetNumber='" + bdLocation.getStreetNumber() + '\'' +
            ", locationDescribe='" + bdLocation.getLocationDescribe() + '\'' +
            ", buildingID='" + bdLocation.getBuildingID() + '\'' +
            ", buildingName='" + bdLocation.getBuildingName() + '\'' +
            ", floor='" + bdLocation.getFloor() + '\'' +
            ", speed=" + bdLocation.getSpeed() + '\'' +
            ", satelliteNumber=" + bdLocation.getSatelliteNumber() + '\'' +
            ", altitude=" + bdLocation.getAltitude() + '\'' +
            ", direction=" + bdLocation.getDirection() + '\'' +
            ", operators=" + bdLocation.getOperators() + '\'' +
            "}";
    Log.d("@@@", str);
    Log.d("@@@", "====================BDLocation End====================");
}
 
Example #23
Source File: TrackerService.java    From LocationProvider with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation bdLocation) {
    Log.d(TAG, "TrackerService onReceiveLocation");
    if (BaiduUtils.isValidLocation(bdLocation, cashLocation)) {
        BaiduUtils.prinftBDLocation(bdLocation);
        HooweLocation location = BaiduUtils.assemblyLocation(bdLocation);
        // 将数据插入数据库
        LocationDBHelper.getHelper(TrackerService.this).locationInsert(location);
    }
}
 
Example #24
Source File: InviteBll.java    From PlayTogether with Apache License 2.0 5 votes vote down vote up
/**
 * 获得发邀请人的地址
 *
 * @param context
 * @return
 */
public Observable<AVGeoPoint> getLocation(final Context context)
{
	return Observable.create(new Observable.OnSubscribe<AVGeoPoint>()
	{
		@Override
		public void call(final Subscriber<? super AVGeoPoint> subscriber)
		{
			LocationClient client = LocationUtils.getLocationClient(context);
			client.registerLocationListener(new BDLocationListener()
			{
				@Override
				public void onReceiveLocation(BDLocation location)
				{
					if (location.getLocType() == BDLocation.TypeGpsLocation || location
									.getLocType() == BDLocation.TypeNetWorkLocation || location
									.getLocType() == BDLocation.TypeOffLineLocation)
					{
						subscriber.onNext(new AVGeoPoint(location.getLatitude(), location
										.getLongitude()));
					} else
					{
						subscriber.onNext(null);
					}
					LocationUtils.stopClient();
				}
			});
			client.start();
		}
	});
}
 
Example #25
Source File: LocationActivity.java    From Conquer with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
	// map view 销毁后不在处理新接收的位置
	if (location == null || mMapView == null) return;

	if (lastLocation != null) {
		if (lastLocation.getLatitude() == location.getLatitude() && lastLocation.getLongitude() == location.getLongitude()) {
			BmobLog.i("获取坐标相同");// 若两次请求获取到的地理位置坐标是相同的,则不再定位
			mLocClient.stop();
			return;
		}
	}
	lastLocation = location;

	BmobLog.i("lontitude = " + location.getLongitude() + ",latitude = " + location.getLatitude() + ",地址 = "
			+ lastLocation.getAddrStr());

	MyLocationData locData = new MyLocationData.Builder().accuracy(location.getRadius())
	// 此处设置开发者获取到的方向信息,顺时针0-360
			.direction(100).latitude(location.getLatitude()).longitude(location.getLongitude()).build();
	mBaiduMap.setMyLocationData(locData);
	LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());
	String address = location.getAddrStr();
	if (address != null && !address.equals("")) {
		lastLocation.setAddrStr(address);
	} else {
		// 反Geo搜索
		mSearch.reverseGeoCode(new ReverseGeoCodeOption().location(ll));
	}
	// 显示在地图上
	MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
	mBaiduMap.animateMapStatus(u);
	// 设置按钮可点击
	// mHeaderLayout.getRightImageButton().setEnabled(true);
}
 
Example #26
Source File: MapPickerActivity.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
    if (null != location && location.getLocType() != BDLocation.TypeServerError) {
        //

        MyLocationData data = new MyLocationData.Builder()//
                // .direction(mCurrentX)//
                .accuracy(location.getRadius())//
                .latitude(location.getLatitude())//
                .longitude(location.getLongitude())//
                .build();
        mBaiduMap.setMyLocationData(data);
        // 设置自定义图标
        MyLocationConfiguration config = new MyLocationConfiguration(
                MyLocationConfiguration.LocationMode.NORMAL, true, null);
        mBaiduMap.setMyLocationConfigeration(config);
        mAddress = location.getAddrStr();
        mName = location.getStreet();
        mCity = location.getCity();

        LatLng currentLatLng = new LatLng(location.getLatitude(), location.getLongitude());
        mLoactionLatLng = currentLatLng;
        // 是否第一次定位
        if (isFirstLoc) {
            isFirstLoc = false;
            // 实现动画跳转
            MapStatusUpdate u = MapStatusUpdateFactory
                    .newLatLng(currentLatLng);
            mBaiduMap.animateMapStatus(u);
            mGeoCoder.reverseGeoCode((new ReverseGeoCodeOption())
                    .location(currentLatLng));
            return;
        }
    }

}
 
Example #27
Source File: AsyncLocationResultListener.java    From VirtualLocation with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
    // map view 销毁后不在处理新接收的位置
    if (location == null || mMapView == null) {
        return;
    }

    if (isFirstLoc) {
        isFirstLoc = false;
        MainActivity.myGpslatitude = location.getLatitude();
        MainActivity.myGpslongitude = location.getLongitude();
        LatLng ll = new LatLng(myGpslatitude, myGpslongitude);
        setCurrentMapLatLng(ll);
    }
}
 
Example #28
Source File: LocationClient.java    From FakeWeather with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example #29
Source File: WeatherPresenter.java    From AndroidDemo with MIT License 5 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation bdLocation) {
    weatherView.hideRequestWindow();
    if (bdLocation != null) {
        String district = bdLocation.getDistrict();
        String city = bdLocation.getCity();
        String address = district.substring(0, district.length() - 1) + "," + city.substring(0, city.length() - 1);
        weatherView.setLocation(address);
    }
}
 
Example #30
Source File: LocationActivity.java    From VSigner with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
	hideProgressDialog();
	if (location == null || StrUtil.isEmpty(location.getAddrStr())) {
		ShowToast(getString(R.string.location_error));
		return;
	}
	mLocation = location;
	mLatitudeTextView.setText(String.valueOf(location.getLatitude()));
	mLongtitudeTextView.setText(String.valueOf(location.getLongitude()));
	mAddressTextView.setText(location.getAddrStr());
	mRefreshTextView.setText(String.format(getString(R.string.refresh_time_format), location.getTime()));
}