本文整理汇总了Java中com.amap.api.location.AMapLocation类的典型用法代码示例。如果您正苦于以下问题:Java AMapLocation类的具体用法?Java AMapLocation怎么用?Java AMapLocation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AMapLocation类属于com.amap.api.location包,在下文中一共展示了AMapLocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initLocation
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
private void initLocation() {
mLocationClient = new AMapLocationClient(this);
AMapLocationClientOption option = new AMapLocationClientOption();
option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
option.setOnceLocation(true);
mLocationClient.setLocationOption(option);
mLocationClient.setLocationListener(new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (aMapLocation != null) {
if (aMapLocation.getErrorCode() == 0) {
String city = aMapLocation.getCity();
String district = aMapLocation.getDistrict();
String location = StringUtils.extractLocation(city, district);
mCityAdapter.updateLocateState(LocateState.SUCCESS, location);
} else {
//定位失败
mCityAdapter.updateLocateState(LocateState.FAILED, null);
}
}
}
});
}
示例2: onLocationChanged
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (mListener != null && aMapLocation != null) {
if (aMapLocation != null && aMapLocation.getErrorCode() == 0) {
mAMapLocation = aMapLocation;
mlocationClient.stopLocation();
mListener.onLocationChanged(aMapLocation);// 显示系统小蓝点
lp = new LatLonPoint(aMapLocation.getLatitude(), aMapLocation.getLongitude());
mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lp.getLatitude(), lp.getLongitude()), 17));
doSearchQuery(aMapLocation.getPoiName().trim(), aMapLocation.getCityCode(), false);
} else {
String errText = "定位失败," + aMapLocation.getErrorCode() + ": " + aMapLocation.getErrorInfo();
ToastUtils.showToast(this, errText);
}
}
}
示例3: onLocationChanged
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (aMapLocation != null) {
if (aMapLocation.getErrorCode() == 0) {
String lat = aMapLocation.getLatitude() + "";
String lng = aMapLocation.getLongitude() + "";
sharedPref.edit().putString("Latitude", lat).apply();
sharedPref.edit().putString("Longitude", lng).apply();
} else {
Toast.makeText(
MainActivity.this,
aMapLocation.getErrorInfo(),
Toast.LENGTH_LONG
).show();
}
}
}
示例4: setCity
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
/**
* 设置当前城市
* @param amapLocation
*/
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void setCity(AMapLocation amapLocation) {
if(amapLocation!=null){
this.city = amapLocation.getCity();
}
}
示例5: onLocationChanged
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
/**
* 实现定位
* @param amapLocation
*/
@Override
public void onLocationChanged(AMapLocation amapLocation) {
if (mListener != null && amapLocation != null) {
if (amapLocation != null
&&amapLocation.getErrorCode() == 0) {
if(isFirstTime){//只要第一次的数据,当然,也可以在这里关闭定位
// mlocationClient.stopLocation();//停止定位
mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
lvHolder.title = "[位置]";
lvHolder.address = amapLocation.getProvider()+amapLocation.getCity()+amapLocation.getStreet()+amapLocation.getStreetNum();
lvHolder.lp = new LatLonPoint(amapLocation.getLatitude(),amapLocation.getLongitude());
mEndMarker.setPosition(new LatLng(amapLocation.getLatitude(),amapLocation.getLongitude()));
data.add(0,lvHolder);
doSearchQuery();
}
} else {
String errText = "定位失败," + amapLocation.getErrorCode()+ ": " + amapLocation.getErrorInfo();
Log.e("AmapErr",errText);
}
}
}
示例6: onLocationChanged
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
/**
* 定位地点
* @param amapLocation
*/
@Override
public void onLocationChanged(AMapLocation amapLocation) {
if (mListener != null&&amapLocation != null) {
EventBus.getDefault().post(amapLocation);
if (amapLocation != null
&&amapLocation.getErrorCode() == 0) {
if(startList.size()==0)
startList.add(new NaviLatLng(amapLocation.getLatitude(),amapLocation.getLongitude()));
if(!calculateSuccess){
mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
}
} else {
String errText = "定位失败," + amapLocation.getErrorCode()+ ": " + amapLocation.getErrorInfo();
Log.e("AmapErr",errText);
}
}
}
示例7: notifyLocationChanged
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
@Override
public void notifyLocationChanged(LocationSource.OnLocationChangedListener amListener, AMapLocation aMapLocation) {
if(mGpsPowerListener != null){
mGpsPowerListener.onGpsPower(aMapLocation.getGpsAccuracyStatus());
}
for(ILocationFilter locationFilter : mLocationFilterList) {
if(!locationFilter.accept(mPrevoiusLocation, aMapLocation)){
return;
}
}
mPrevoiusLocation = aMapLocation;
amListener.onLocationChanged(aMapLocation);
if(mOnNewLocationListener != null){
mOnNewLocationListener.onNewLocation(aMapLocation);
}
}
示例8: accept
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
@Override
public boolean accept(AMapLocation previous, AMapLocation current) {
if(previous == null){
return true;
}
LatLng pre = new LatLng(previous.getLatitude(), previous.getLongitude());
LatLng cur = new LatLng(current.getLatitude(), current.getLongitude());
float distance = AMapUtils.calculateLineDistance(pre, cur);
if(distance < RMConfiguration.DRAW_DISTANCE){
return false;
}
float speed = current.getSpeed();
double interval = (SystemClock.elapsedRealtime() - mPreviousUpdateTime)/1000.0;
float v = (float) (distance/interval);
if(v > RMConfiguration.MAX_SPEED || v > speed * 1.5){
return false;
}
mPreviousUpdateTime = SystemClock.elapsedRealtime();
return true;
}
示例9: fun_getGeolocation
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
@JavascriptInterface
public void fun_getGeolocation(String jsonString) {
JSInBean jsInBean = JSBridgeUtil.getInstance().parseJsonArray(jsonString);
StringBuilder builder = new StringBuilder();
AMapLocation location = AMapLocationTool.getInstance().location();
builder.append("{");
builder.append("\"permission\":" + (this.mActivity.getPackageManager().checkPermission("android.permission.ACCESS_COARSE_LOCATION", BaseApplication.getInstance().getPackageName()) == 0 ? "1" : "0") + ",");
builder.append("\"longitude\":" + location.getLongitude() + ",");
builder.append("\"latitude\":" + location.getLatitude() + ",");
builder.append("\"horizontalAccuracy\":0,");
builder.append("\"verticalAccuracy\":0,");
builder.append("\"altitude\":" + location.getAltitude() + ",");
builder.append("\"altitudeAccuracy\":0");
builder.append("}");
jsCallBack(jsInBean, builder.toString());
}
示例10: location
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
public synchronized AMapLocation location() {
if (!this.isStart) {
if (this.mLocationClient != null) {
this.mLocationClient.setLocationListener(this.myListener);
setLocationOption();
this.mLocationClient.startLocation();
this.isStart = true;
} else {
this.mLocationClient = new AMapLocationClient(BaseApplication.getInstance().getBaseContext());
this.mLocationClient.setLocationListener(this.myListener);
setLocationOption();
this.mLocationClient.startLocation();
this.isStart = true;
}
}
this.mHandler.postDelayed(new 1(this), 5000);
if (this.mLocationClient != null) {
AMapLocation location = this.mLocationClient.getLastKnownLocation();
if (location != null) {
this.lastBdLocation = location;
}
}
return this.lastBdLocation;
}
示例11: statisticsLoginAndEnv
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
public static void statisticsLoginAndEnv(Context context, int st, boolean isLogin) {
String loginProperty = "plat=" + LetvConfig.getSource();
AMapLocation location = AMapLocationTool.getInstance().location();
String lo = "";
String la = "";
if (location != null) {
lo = String.valueOf(location.getLongitude());
la = String.valueOf(location.getLatitude());
}
if (TextUtils.isEmpty(lo) && TextUtils.isEmpty(la)) {
lo = PreferencesManager.getInstance().getLocationLongitude() + "";
la = PreferencesManager.getInstance().getLocationLatitude() + "";
}
int i = st;
DataStatistics.getInstance().sendLoginAndEnvInfo(context.getApplicationContext(), LetvUtils.getUID(), loginProperty, sLoginRef, String.valueOf(System.currentTimeMillis() / 1000), LetvUtils.getPcode(), i, null, LetvConfig.getSource(), lo, la, PreferencesManager.getInstance().getStatisticsLocation(), isLogin);
}
示例12: initLocation
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
/**
* 初始化百度地图
*/
private void initLocation() {
AMapLocation location = locationClient.getLastKnownLocation();
if (location != null) {
Log.d(TAG, "getLastKnownLocation success");
mLongitude = location.getLongitude();
mLatitude = location.getLatitude();
city = location.getCity();
country = location.getCountry();
Log.d("XLight", String.format("long:%s,latitude:%s,ciry:%s,country:%s", mLongitude, mLatitude, city, country));
//请求天气信息
updateLocationInfo();
} else {
// 启动定位
locationClient.startLocation();
}
}
示例13: onLocationChanged
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
@Override
public void onLocationChanged(AMapLocation loc) {
if (null != loc && loc.getErrorCode() == 0) {
//解析定位结果
mLongitude = loc.getLongitude();
mLatitude = loc.getLatitude();
city = loc.getCity();
country = loc.getCountry();
Log.i("XLight", String.format("long:%s,latitude:%s,city:%s,country:%s", mLongitude, mLatitude, city, country));
//请求天气信息
updateLocationInfo();
locationClient.stopLocation();
} else {
// 定位失败,显示提示
Log.e("XLight", "location Error, ErrCode:"
+ loc.getErrorCode() + ", errInfo:"
+ loc.getErrorInfo());
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
ToastUtil.showToast(getActivity(), R.string.open_gps);
}
});
}
}
示例14: onLocationChanged
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (aMapLocation != null) {
if (aMapLocation.getErrorCode() == 0) {
mCity = aMapLocation.getCity();
mSwipeRefreshLayout.setEnabled(true);
mSwipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(true);
}
});
getWeatherData(mCity);
}
//定位失败,通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息
else {
SnackBarUtil.showSnackBar(aMapLocation.getErrorInfo(), mSwipeRefreshLayout, getActivity());
}
}
}
示例15: initLocation
import com.amap.api.location.AMapLocation; //导入依赖的package包/类
private void initLocation() {
mLocationClient = new AMapLocationClient(this);
AMapLocationClientOption option = new AMapLocationClientOption();
option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
option.setOnceLocation(true);
mLocationClient.setLocationOption(option);
mLocationClient.setLocationListener(new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (aMapLocation != null) {
if (aMapLocation.getErrorCode() == 0) {
String city = aMapLocation.getCity();
String district = aMapLocation.getDistrict();
Log.e("onLocationChanged", "city: " + city);
Log.e("onLocationChanged", "district: " + district);
String location = StringUtils.extractLocation(city, district);
mCityAdapter.updateLocateState(LocateState.SUCCESS, location);
} else {
//定位失败
mCityAdapter.updateLocateState(LocateState.FAILED, null);
}
}
}
});
mLocationClient.startLocation();
}