本文整理匯總了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();
}