Java Code Examples for com.amap.api.location.AMapLocation#getErrorCode()

The following examples show how to use com.amap.api.location.AMapLocation#getErrorCode() . 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: GeoFence_Multiple_Activity.java    From Android_Location_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * 定位成功后回调函数
 */
@Override
public void onLocationChanged(AMapLocation amapLocation) {
	if (mListener != null && amapLocation != null) {
		if (amapLocation != null && amapLocation.getErrorCode() == 0) {
			tvResult.setVisibility(View.GONE);
			mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
		} else {
			String errText = "定位失败," + amapLocation.getErrorCode() + ": "
					+ amapLocation.getErrorInfo();
			Log.e("AmapErr", errText);
			tvResult.setVisibility(View.VISIBLE);
			tvResult.setText(errText);
		}
	}
}
 
Example 2
Source File: GeoFence_Multiple_Activity.java    From Android_Location_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * 定位成功后回调函数
 */
@Override
public void onLocationChanged(AMapLocation amapLocation) {
	if (mListener != null && amapLocation != null) {
		if (amapLocation != null && amapLocation.getErrorCode() == 0) {
			tvResult.setVisibility(View.GONE);
			mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
		} else {
			String errText = "定位失败," + amapLocation.getErrorCode() + ": "
					+ amapLocation.getErrorInfo();
			Log.e("AmapErr", errText);
			tvResult.setVisibility(View.VISIBLE);
			tvResult.setText(errText);
		}
	}
}
 
Example 3
Source File: GeoFence_Nearby_Activity.java    From Android_Location_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * 定位成功后回调函数
 */
@Override
public void onLocationChanged(AMapLocation amapLocation) {
	if (mListener != null && amapLocation != null) {
		if (amapLocation != null && amapLocation.getErrorCode() == 0) {
			tvResult.setVisibility(View.GONE);
			mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
		} else {
			String errText = "定位失败," + amapLocation.getErrorCode() + ": "
					+ amapLocation.getErrorInfo();
			Log.e("AmapErr", errText);
			tvResult.setVisibility(View.VISIBLE);
			tvResult.setText(errText);
		}
	}
}
 
Example 4
Source File: GeoFence_Keyword_Activity.java    From Android_Location_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * 定位成功后回调函数
 */
@Override
public void onLocationChanged(AMapLocation amapLocation) {
	if (mListener != null && amapLocation != null) {
		if (amapLocation != null && amapLocation.getErrorCode() == 0) {
			tvResult.setVisibility(View.GONE);
			mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
		} else {
			String errText = "定位失败," + amapLocation.getErrorCode() + ": "
					+ amapLocation.getErrorInfo();
			Log.e("AmapErr", errText);
			tvResult.setVisibility(View.VISIBLE);
			tvResult.setText(errText);
		}
	}
}
 
Example 5
Source File: GeoFence_Keyword_Activity.java    From Android_Location_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * 定位成功后回调函数
 */
@Override
public void onLocationChanged(AMapLocation amapLocation) {
	if (mListener != null && amapLocation != null) {
		if (amapLocation != null && amapLocation.getErrorCode() == 0) {
			tvResult.setVisibility(View.GONE);
			mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
		} else {
			String errText = "定位失败," + amapLocation.getErrorCode() + ": "
					+ amapLocation.getErrorInfo();
			Log.e("AmapErr", errText);
			tvResult.setVisibility(View.VISIBLE);
			tvResult.setText(errText);
		}
	}
}
 
Example 6
Source File: MapActivity.java    From WechatHook-Dusan with Apache License 2.0 6 votes vote down vote up
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
    if (aMapLocation != null
            && aMapLocation.getErrorCode() == 0) {
        //longitude = aMapLocation.getLongitude();
        //latitude = aMapLocation.getLatitude();
        if (!aMapLocation.getCountry().equals("中国")){
            changeToGoogleMapView();
        } else {
            amap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,longitude), 15));
        }
        //Toast.makeText(context,aMapLocation.getCountry(),Toast.LENGTH_LONG).show();
        mIsAuto = false;
        mcheckbtn.setChecked(false);
        //setCurrentPositionInfo();
    } else {
        String errText = "定位失败," + aMapLocation.getErrorCode() + ": " + aMapLocation.getErrorInfo();
        LogUtils.debug("AmapErr", errText);
        Toast.makeText(context, errText, Toast.LENGTH_LONG).show();
    }
}
 
Example 7
Source File: GeoFence_Round_Activity.java    From Android_Location_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * 定位成功后回调函数
 */
@Override
public void onLocationChanged(AMapLocation amapLocation) {
	if (mListener != null && amapLocation != null) {
		if (amapLocation != null && amapLocation.getErrorCode() == 0) {
			tvResult.setVisibility(View.GONE);
			mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
		} else {
			String errText = "定位失败," + amapLocation.getErrorCode() + ": "
					+ amapLocation.getErrorInfo();
			Log.e("AmapErr", errText);
			tvResult.setVisibility(View.VISIBLE);
			tvResult.setText(errText);
		}
	}
}
 
Example 8
Source File: MainActivity.java    From RecordPath3D with Apache License 2.0 6 votes vote down vote up
@Override
public void onLocationChanged(AMapLocation amapLocation) {
	if (mListener != null && amapLocation != null) {
		if (amapLocation != null && amapLocation.getErrorCode() == 0) {
			mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
			LatLng mylocation = new LatLng(amapLocation.getLatitude(),
					amapLocation.getLongitude());
			mAMap.moveCamera(CameraUpdateFactory.changeLatLng(mylocation));
			if (btn.isChecked()) {
				record.addpoint(amapLocation);
				mPolyoptions.add(mylocation);
				redrawline();
			}
		} else {
			String errText = "定位失败," + amapLocation.getErrorCode() + ": "
					+ amapLocation.getErrorInfo();
			Log.e("AmapErr", errText);
		}
	}
}
 
Example 9
Source File: GeoFence_Polygon_Activity.java    From Android_Location_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * 定位成功后回调函数
 */
@Override
public void onLocationChanged(AMapLocation amapLocation) {
	if (mListener != null && amapLocation != null) {
		if (amapLocation != null && amapLocation.getErrorCode() == 0) {
			tvResult.setVisibility(View.GONE);
			mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
		} else {
			String errText = "定位失败," + amapLocation.getErrorCode() + ": "
					+ amapLocation.getErrorInfo();
			Log.e("AmapErr", errText);
			tvResult.setVisibility(View.VISIBLE);
			tvResult.setText(errText);
		}
	}
}
 
Example 10
Source File: MainActivity.java    From Ency with Apache License 2.0 5 votes vote down vote up
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
    if (aMapLocation != null) {
        if (aMapLocation.getErrorCode() == 0) {
            mPresenter.getWeather(aMapLocation.getCity());
        }
        //定位失败,通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息
        else {
            LogUtil.e("AmapError", "location Error, ErrCode:" + aMapLocation.getErrorCode() + ", errInfo:" + aMapLocation.getErrorInfo());
        }
    }
}
 
Example 11
Source File: MapSimFragment.java    From AndroidSDK with MIT License 5 votes vote down vote up
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
    mProgressDialog.dismiss();
    if (aMapLocation != null && aMapLocation.getErrorCode() == 0) {
        mCorrectedLatLng = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());
        mRealLatLng = getRealLatLng(mCorrectedLatLng);
        mAmap.animateCamera(CameraUpdateFactory.zoomTo(17));
        mAmap.animateCamera(CameraUpdateFactory.changeLatLng(mCorrectedLatLng));
        mLocationTextView.setText("lon: " + aMapLocation.getLongitude() + "° / lat: " + aMapLocation.getLatitude() + "°");
        mAmap.clear();
        mAmap.addMarker(new MarkerOptions().position(mCorrectedLatLng));
    }
}
 
Example 12
Source File: AMapStateListenerImpl.java    From RunMap with Apache License 2.0 5 votes vote down vote up
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
    CFLog.i("TAG","onLocationChanged="+aMapLocation.toString());
    if(mLocationChangedListener != null && aMapLocation != null && aMapLocation.getErrorCode() == 0){
        mStateListener.notifyLocationChanged(mLocationChangedListener,aMapLocation);
    }

}
 
Example 13
Source File: MapActivity.java    From xposed-rimet with Apache License 2.0 5 votes vote down vote up
@Override
public void onLocationChanged(AMapLocation aMapLocation) {

    if (mOnLocationChangedListener == null || mAMapLocationClient == null
            || aMapLocation == null || aMapLocation.getErrorCode() != 0) {
        // 定位失败了
        deactivate();
        ToastUtil.show("定位失败,请开启定位后再重新尝试!");
        return;
    }

    // 当前位置
    LatLng curLatLng = MapUtil.newLatLng(aMapLocation);

    // 通知位置信息
    mOnLocationChangedListener.onLocationChanged(aMapLocation);

    if (mCurMarker == null) {
        // 设置当前位置
        mCurMarker = mAMap.addMarker(new MarkerOptions()
                .anchor(0.5f,0.5f)
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.location_marker)));
    }

    // 移动到指定位置
    mCurMarker.setPosition(curLatLng);

    // 移动到当前位置
    mAMap.animateCamera(CameraUpdateFactory.newLatLngZoom(curLatLng, 16f));
}
 
Example 14
Source File: AmapLocationPlugin.java    From location_plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void onLocationChanged(AMapLocation amapLocation) {
	if (amapLocation != null) {
		if (amapLocation.getErrorCode() == 0) {

			mLocation = getLocationInfoMap(amapLocation);
			mEventSink.success(mLocation);
			Log.d("onLocationChanged", mLocation);
		}
	}
}
 
Example 15
Source File: CustomLocationModeActivity.java    From TraceByAmap with MIT License 5 votes vote down vote up
/**
 * 定位成功后回调函数
 */
@Override
public void onLocationChanged(AMapLocation amapLocation) {
	if (mListener != null && amapLocation != null) {
		if (amapLocation != null
				&& amapLocation.getErrorCode() == 0) {
			LatLng latLng = new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude());
			//展示自定义定位小蓝点
			if(locationMarker == null) {
				//首次定位
				locationMarker = aMap.addMarker(new MarkerOptions().position(latLng)
						.icon(BitmapDescriptorFactory.fromResource(R.drawable.location_marker))
						.anchor(0.5f, 0.5f));

				//首次定位,选择移动到地图中心点并修改级别到15级
				aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
			} else {

				if(useMoveToLocationWithMapMode) {
					//二次以后定位,使用sdk中没有的模式,让地图和小蓝点一起移动到中心点(类似导航锁车时的效果)
					startMoveLocationAndMap(latLng);
				} else {
					startChangeLocation(latLng);
				}
				
			}


		} else {
			String errText = "定位失败," + amapLocation.getErrorCode()+ ": " + amapLocation.getErrorInfo();
			Log.e("AmapErr",errText);
		}
	}
}
 
Example 16
Source File: LocationService.java    From OpenWeatherPlus-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
    if (aMapLocation.getErrorCode() == 0) {
        ContentUtil.NOW_LON = aMapLocation.getLongitude();
        ContentUtil.NOW_LAT = aMapLocation.getLatitude();
        Log.i(TAG, "now location: " +  ContentUtil.NOW_LON + "," + ContentUtil.NOW_LAT);
    }else {
        String errText = "定位失败," + aMapLocation.getErrorCode() + ": " + aMapLocation.getErrorInfo();
        Log.e(TAG, errText);
    }
}
 
Example 17
Source File: AMapLocationService.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
    cancel();
    if (callback != null) {
        switch (aMapLocation.getErrorCode()) {
            case 0:
                Result result = new Result(
                        (float) aMapLocation.getLatitude(),
                        (float) aMapLocation.getLongitude()
                );
                result.setGeocodeInformation(
                        aMapLocation.getCountry(),
                        aMapLocation.getProvince(),
                        aMapLocation.getCity(),
                        aMapLocation.getDistrict()
                );
                result.inChina = CoordinateConverter.isAMapDataAvailable(
                        aMapLocation.getLatitude(),
                        aMapLocation.getLongitude()
                );
                callback.onCompleted(result);
                break;

            default:
                BuglyHelper.report(
                        new LocationException(
                                aMapLocation.getErrorCode(),
                                aMapLocation.getErrorInfo()
                        )
                );
                callback.onCompleted(null);
                break;
        }
    }
}
 
Example 18
Source File: NewLocationManager.java    From NewFastFrame with Apache License 2.0 4 votes vote down vote up
@Override
    public void onLocationChanged(AMapLocation aMapLocation) {
        if (aMapLocation != null) {
            if (aMapLocation.getErrorCode() == 0) {
                CommonLogger.e("1获取到位置信息拉");
                //                获取纬度
                if (latitude != aMapLocation.getLatitude() || longitude != aMapLocation.getLongitude()) {
                    latitude = aMapLocation.getLatitude();
                    //                获取经度
                    longitude = aMapLocation.getLongitude();
                    address = aMapLocation.getAddress();
                    CommonLogger.e(aMapLocation.toString());
//                                        aMapLocation.getLocationType();//获取当前定位结果来源
//                                        aMapLocation.getLatitude();//获取纬度
//                                        aMapLocation.getLongitude();//获取经度
//                                        aMapLocation.getAccuracy();//获取精度信息
//                                        aMapLocation.getAddress();//地址,如果option中设置isNeedAddress为false,则没有此结果,网络定位结果中会有地址信息,GPS定位不返回地址信息。
//                                        aMapLocation.getCountry();//国家信息
//                                        aMapLocation.getProvince();//省信息
//                                        aMapLocation.getCity();//城市信息
//                                        aMapLocation.getDistrict();//城区信息
//                                        aMapLocation.getStreet();//街道信息
//                                        aMapLocation.getStreetNum();//街道门牌号信息
//                                        aMapLocation.getCityCode();//城市编码
//                                        aMapLocation.getAdCode();//地区编码
//                                        aMapLocation.getAoiName();//获取当前定位点的AOI信息
                    LocationEvent locationEvent = new LocationEvent();
                    locationEvent.setLongitude(longitude);
                    locationEvent.setLatitude(latitude);
                    locationEvent.setLocation(address);
                    locationEvent.setCountry(aMapLocation.getCountry());
                    locationEvent.setProvince(aMapLocation.getProvince());
                    locationEvent.setCity(aMapLocation.getCity());
                    locationEvent.setTitle(aMapLocation.getPoiName());
                    RxBusManager.getInstance().post(locationEvent);
                    BaseApplication.getAppComponent().getSharedPreferences().edit().putString(ConstantUtil.LATITUDE, latitude+"")
                            .putString(ConstantUtil.LONGITUDE,longitude+"")
                            .putString(ConstantUtil.ADDRESS, address)
                    .putString(ConstantUtil.CITY,aMapLocation.getCity()).apply();
                    if (UserManager.getInstance().getCurrentUser() != null) {
                        UserManager.getInstance().updateUserInfo(ConstantUtil.LOCATION,longitude+"&"+latitude,null);
                    }
                } else {
                    CommonLogger.e("定位相同,不定位");
                }
            } else {
                CommonLogger.e("出错消息:" + aMapLocation.getErrorInfo() + "\n" + "错误码:" + aMapLocation.getErrorCode() + "\n" + "错误的细节" +
                        aMapLocation.getLocationDetail());
            }
        }
    }
 
Example 19
Source File: MainActivity.java    From PoetryWeather with Apache License 2.0 4 votes vote down vote up
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
    if (aMapLocation != null) {
        if (aMapLocation.getErrorCode() == 0) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    districtName = aMapLocation.getDistrict();
                    if (districtName.substring(districtName.length()-1).equals("区")) {
                        districtName = districtName.substring(0, districtName.length() - 1);
                        Log.d(TAG, "onSuccess: 修改后区县位置"+districtName);
                    }
                    Log.d(TAG, "onLocationChanged: "+districtName);
                    HeWeather.getSearch(MainActivity.this, districtName, "cn", 1, CHINESE_SIMPLIFIED, new HeWeather.OnResultSearchBeansListener() {
                        @Override
                        public void onError(Throwable throwable) {
                            Log.i(TAG, "onError: ",throwable);
                            Toast.makeText(MainActivity.this,"城市搜索失败",Toast.LENGTH_SHORT).show();

                        }

                        @Override
                        public void onSuccess(Search search) {
                            //可在其中解析aMapLocation获取相应内容。
                            Log.d(TAG, "onLocationChanged: "+aMapLocation.getProvince());
                            Log.d(TAG, "onLocationChanged: "+aMapLocation.getDistrict());
                            provinceName = aMapLocation.getProvince();

                            for (Basic basic : search.getBasic()) {
                                String cid = basic.getCid();
                                cityCode = cid.substring(2);
                                Log.d(TAG, "onSuccess: cityCode"+cityCode);
                            }
                            if (!getFirst()) {
                                Message message = new Message();
                                message.what = UPDATE_TEXT;
                                handler.sendMessage(message);
                            }
                        }
                    });
                }
            }).start();
            mLocationClient.stopLocation();
            //销毁定位客户端,同时销毁本地定位服务。
            mLocationClient.onDestroy();
        }else {
            //定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息,详见错误码表。
            Log.e("AmapError","location Error, ErrCode:"
                    + aMapLocation.getErrorCode() + ", errInfo:"
                    + aMapLocation.getErrorInfo());
        }
    }
}
 
Example 20
Source File: AMapUtils.java    From myapplication with Apache License 2.0 4 votes vote down vote up
/**
     * 根据定位结果返回定位信息的字符串
     *
     * @param location
     * @return
     */
    public synchronized static String getLocationStr(AMapLocation location) {
        if (null == location) {
            return null;
        }
        StringBuffer sb = new StringBuffer();
        //errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明
        if (location.getErrorCode() == 0) {
//			sb.append("定位成功" + "\n");
//			sb.append("定位类型: " + location.getLocationType() + "\n");
//			sb.append("经    度    : " + location.getLongitude() + "\n");
//			sb.append("纬    度    : " + location.getLatitude() + "\n");
//			sb.append("精    度    : " + location.getAccuracy() + "米" + "\n");
//			sb.append("提供者    : " + location.getProvider() + "\n");

//			if (location.getProvider().equalsIgnoreCase(
//					android.location.LocationManager.GPS_PROVIDER)) {
//				// 以下信息只有提供者是GPS时才会有
//				sb.append("速    度    : " + location.getSpeed() + "米/秒" + "\n");
//				sb.append("角    度    : " + location.getBearing() + "\n");
//				// 获取当前提供定位服务的卫星个数
//				sb.append("星    数    : "
//						+ location.getSatellites() + "\n");
//			} else {
            // 提供者是GPS时是没有以下信息的
//            sb.append(location.getCountry() + " ");
            sb.append(location.getProvince() + " ");
            sb.append(location.getCity() + " ");
//				sb.append("城市编码 : " + location.getCityCode() + "\n");
            sb.append(location.getDistrict());
//				sb.append("区域 码   : " + location.getAdCode() + "\n");
//				sb.append("地    址    : " + location.getAddress() + "\n");
//				sb.append("兴趣点    : " + location.getPoiName() + "\n");
//			}
        } else {
            //定位失败
            sb.append("定位失败" + "\n");
            sb.append("错误码:" + location.getErrorCode() + "\n");
            sb.append("错误信息:" + location.getErrorInfo() + "\n");
            sb.append("错误描述:" + location.getLocationDetail() + "\n");
        }
        return sb.toString();
    }