com.amap.api.location.AMapLocation Java Examples
The following examples show how to use
com.amap.api.location.AMapLocation.
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 RecordPath3D with Apache License 2.0 | 6 votes |
private float getDistance(List<AMapLocation> list) { float distance = 0; if (list == null || list.size() == 0) { return distance; } for (int i = 0; i < list.size() - 1; i++) { AMapLocation firstpoint = list.get(i); AMapLocation secondpoint = list.get(i + 1); LatLng firstLatLng = new LatLng(firstpoint.getLatitude(), firstpoint.getLongitude()); LatLng secondLatLng = new LatLng(secondpoint.getLatitude(), secondpoint.getLongitude()); double betweenDis = AMapUtils.calculateLineDistance(firstLatLng, secondLatLng); distance = (float) (distance + betweenDis); } return distance; }
Example #2
Source File: Alarm_Location_Activity.java From Android_Location_Demo with Apache License 2.0 | 6 votes |
public void dispatchMessage(android.os.Message msg) { switch (msg.what) { //开始定位 case Utils.MSG_LOCATION_START: tvReult.setText("正在定位..."); break; // 定位完成 case Utils.MSG_LOCATION_FINISH: AMapLocation loc = (AMapLocation) msg.obj; String result = Utils.getLocationStr(loc); tvReult.setText(result); break; //停止定位 case Utils.MSG_LOCATION_STOP: tvReult.setText("定位停止"); break; default: break; } }
Example #3
Source File: GeoFence_District_Activity.java From Android_Location_Demo with Apache License 2.0 | 6 votes |
/** * 定位成功后回调函数 */ @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: LocationModeSourceActivity_Old.java From TraceByAmap with MIT License | 6 votes |
/** * 定位成功后回调函数 */ @Override public void onLocationChanged(AMapLocation amapLocation) { if (mListener != null && amapLocation != null) { if (amapLocation != null && amapLocation.getErrorCode() == 0) { mLocationErrText.setVisibility(View.GONE); mListener.onLocationChanged(amapLocation);// 显示系统小蓝点 } else { String errText = "定位失败," + amapLocation.getErrorCode()+ ": " + amapLocation.getErrorInfo(); Log.e("AmapErr",errText); mLocationErrText.setVisibility(View.VISIBLE); mLocationErrText.setText(errText); } } }
Example #5
Source File: MainActivity.java From RecordPath3D with Apache License 2.0 | 6 votes |
protected void saveRecord(List<AMapLocation> list, String time) { if (list != null && list.size() > 0) { DbHepler = new DbAdapter(this); DbHepler.open(); String duration = getDuration(); float distance = getDistance(list); String average = getAverage(distance); String pathlineSring = getPathLineString(list); AMapLocation firstLocaiton = list.get(0); AMapLocation lastLocaiton = list.get(list.size() - 1); String stratpoint = amapLocationToString(firstLocaiton); String endpoint = amapLocationToString(lastLocaiton); DbHepler.createrecord(String.valueOf(distance), duration, average, pathlineSring, stratpoint, endpoint, time); DbHepler.close(); } else { Toast.makeText(MainActivity.this, "没有记录到路径", Toast.LENGTH_SHORT) .show(); } }
Example #6
Source File: GaodeMapLocationManager.java From FimiX8-RE with MIT License | 6 votes |
public void onLocationChanged(AMapLocation amapLocation) { if (this.mListener != null && amapLocation != null) { if (amapLocation == null || amapLocation.getErrorCode() != 0) { Log.e("AmapErr", "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo()); return; } LatLng latLng = new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude()); this.mAccuracy = amapLocation.getAccuracy(); if (this.locationMarker == null) { this.locationMarker = this.aMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.location_map)).anchor(0.5f, 0.5f)); this.aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15.5f)); } else if (this.useMoveToLocationWithMapMode) { startMoveLocationAndMap(latLng); } else { startChangeLocation(latLng); } } }
Example #7
Source File: AMAPLocationActivity.java From sealtalk-android with MIT License | 6 votes |
@Override public void onLocationChanged(AMapLocation aMapLocation) { if (aMapLocation != null && aMapLocation.getAMapException().getErrorCode() == 0) { if (listener != null) { listener.onLocationChanged(aMapLocation);// 显示系统小蓝点 } myLocation = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());//获取当前位置经纬度 tvCurLocation.setText(aMapLocation.getRoad() + aMapLocation.getStreet() + aMapLocation.getPoiName());//当前位置信息 double latitude = aMapLocation.getLatitude(); double longitude = aMapLocation.getLongitude(); mMsg = LocationMessage.obtain(latitude, longitude, aMapLocation.getRoad() + aMapLocation.getStreet() + aMapLocation.getPoiName(), getMapUrl(latitude, longitude)); NLog.e("LocationInit", aMapLocation.getRoad() + aMapLocation.getStreet() + aMapLocation.getPoiName() + latitude + "----" + longitude); addChooseMarker(); } }
Example #8
Source File: MainActivity.java From OpenWeatherPlus-Android with Apache License 2.0 | 6 votes |
@Override public void onLocationChanged(AMapLocation aMapLocation) { if (aMapLocation.getErrorCode() == 0) { ContentUtil.NOW_LON = aMapLocation.getLongitude(); ContentUtil.NOW_LAT = aMapLocation.getLatitude(); getNowCity(true); mLocationClient.onDestroy(); } else { if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { // 没有权限 View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.pop_loc_list, null); LocListWindow locListWindow = new LocListWindow(view, MATCH_PARENT, MATCH_PARENT, MainActivity.this); locListWindow.show(); locListWindow.showAtLocation(tvLocation, Gravity.CENTER, 0, 0); if (ContentUtil.FIRST_OPEN) { ContentUtil.FIRST_OPEN = false; SpUtils.putBoolean(MainActivity.this, "first_open", false); } } getNowCity(true); mLocationClient.onDestroy(); } }
Example #9
Source File: GeoFence_Keyword_Activity.java From Android_Location_Demo with Apache License 2.0 | 6 votes |
/** * 定位成功后回调函数 */ @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: GeoFence_Nearby_Activity.java From Android_Location_Demo with Apache License 2.0 | 6 votes |
/** * 定位成功后回调函数 */ @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 #11
Source File: MapsModule.java From Maps with GNU General Public License v2.0 | 6 votes |
@Override public void onGaodeLocationChanged(AMapLocation aMapLocation) { if ((mLocation == null || (mLocation.getLatitude() != aMapLocation.getLatitude() || mLocation.getLongitude() != aMapLocation.getLongitude()))) { Log.d("MapsAction", "onLocationChanged"); if (mIsEnableMyLocation) { LatLng latLng = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude()); mGaodeMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15)); if (marker == null) { MarkerOptions mMyLocationMarker = new MarkerOptions().anchor(0.5f, 0.5f).position(latLng).icon(mMyLocationIcon); marker = mGaodeMap.addMarker(mMyLocationMarker); } else { marker.setPosition(latLng); } } mLocation = aMapLocation; } }
Example #12
Source File: GeoFence_Old_Activity.java From Android_Location_Demo with Apache License 2.0 | 6 votes |
public void dispatchMessage(android.os.Message msg) { switch (msg.what) { case 1: tvReult.setText("进入围栏区域"); break; case 2: tvReult.setText("离开围栏区域"); break; case -1: // 获取当前位置失败 AMapLocation loc = (AMapLocation) msg.obj; tvReult.setText(Utils.getLocationStr(loc)); btFence.setText(getResources().getString(R.string.addFence)); break; default: break; } }
Example #13
Source File: GeoFence_Old_Activity.java From Android_Location_Demo with Apache License 2.0 | 6 votes |
public void dispatchMessage(android.os.Message msg) { switch (msg.what) { case 1: tvReult.setText("进入围栏区域"); break; case 2: tvReult.setText("离开围栏区域"); break; case -1: // 获取当前位置失败 AMapLocation loc = (AMapLocation) msg.obj; tvReult.setText(Utils.getLocationStr(loc)); btFence.setText(getResources().getString(R.string.addFence)); break; default: break; } }
Example #14
Source File: GeoFence_Nearby_Activity.java From Android_Location_Demo with Apache License 2.0 | 6 votes |
/** * 定位成功后回调函数 */ @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 #15
Source File: GeoFence_Polygon_Activity.java From Android_Location_Demo with Apache License 2.0 | 6 votes |
/** * 定位成功后回调函数 */ @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 #16
Source File: LocationActivity.java From xmpp with Apache License 2.0 | 6 votes |
/** * 定位成功后回调函数 */ @Override public void onLocationChanged(AMapLocation aLocation) { if (mListener != null && aLocation != null && aLocation.getAMapException().getErrorCode() == 0) { mListener.onLocationChanged(aLocation);// 显示系统小蓝点 marker.setPosition(new LatLng(aLocation.getLatitude(), aLocation .getLongitude()));// 定位雷达小图标 float bearing = aMap.getCameraPosition().bearing; aMap.setMyLocationRotateAngle(bearing);// 设置小蓝点旋转角度 aMap.getMinZoomLevel(); double a = aLocation.getLatitude();// 维度 double b = aLocation.getLongitude();// 精度 lp = new LatLonPoint(a, b); doSearchQuery(); } }
Example #17
Source File: LocationManager.java From Android-Application-ZJB with Apache License 2.0 | 6 votes |
@Override public void onLocationChanged(AMapLocation amapLocation) { if (amapLocation != null) { if (amapLocation.getErrorCode() == AMapLocation.LOCATION_SUCCESS) { Logger.e("经度 = " + amapLocation.getLongitude() + "\n" + "纬度 = " + amapLocation.getLatitude()); if (!isWriteData) { writeData(amapLocation); } } else { //显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。 Logger.e("AmapError", "location Error, ErrCode:" + amapLocation.getErrorCode() + ", errInfo:" + amapLocation.getErrorInfo()); } RxBusManager.post(EventConstant.KEY_LOCATION, getLocationBean(amapLocation)); } }
Example #18
Source File: d.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
public static void a(Context context, AMapLocation amaplocation) { try { android.content.SharedPreferences.Editor editor = context.getSharedPreferences("last_know_location", 0).edit(); editor.putString("last_know_lat", String.valueOf(amaplocation.getLatitude())); editor.putString("last_know_lng", String.valueOf(amaplocation.getLongitude())); editor.putString("province", amaplocation.getProvince()); editor.putString("city", amaplocation.getCity()); editor.putString("district", amaplocation.getDistrict()); editor.putString("cityCode", amaplocation.getCityCode()); editor.putString("adCode", amaplocation.getAdCode()); editor.putFloat("accuracy", amaplocation.getAccuracy()); editor.putLong("time", amaplocation.getTime()); editor.commit(); return; } catch (Throwable throwable) { throwable.printStackTrace(); } }
Example #19
Source File: Alarm_Location_Activity.java From Android_Location_Demo with Apache License 2.0 | 6 votes |
public void dispatchMessage(android.os.Message msg) { switch (msg.what) { //开始定位 case Utils.MSG_LOCATION_START: tvReult.setText("正在定位..."); break; // 定位完成 case Utils.MSG_LOCATION_FINISH: AMapLocation loc = (AMapLocation) msg.obj; String result = Utils.getLocationStr(loc); tvReult.setText(result); break; //停止定位 case Utils.MSG_LOCATION_STOP: tvReult.setText("定位停止"); break; default: break; } }
Example #20
Source File: AmapWrapper.java From RunMap with Apache License 2.0 | 6 votes |
@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); } }
Example #21
Source File: AMapUtils.java From myapplication with Apache License 2.0 | 6 votes |
/** * 根据定位结果返回定位信息的字符串 * * @param location * @return */ public synchronized static String getLocationCityStr(AMapLocation location) { if (null == location) { return null; } StringBuffer sb = new StringBuffer(); //errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明 if (location.getErrorCode() == 0) { String tmpSb = location.getCity(); sb.append(tmpSb.substring(0, tmpSb.length() - 1)); } else { //定位失败 sb.append("定位失败" + "\n"); sb.append("错误码:" + location.getErrorCode() + "\n"); sb.append("错误信息:" + location.getErrorInfo() + "\n"); sb.append("错误描述:" + location.getLocationDetail() + "\n"); } Log.d("AMapUtils", sb.toString()); return sb.toString(); }
Example #22
Source File: GeoFence_Round_Activity.java From Android_Location_Demo with Apache License 2.0 | 6 votes |
/** * 定位成功后回调函数 */ @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 #23
Source File: StatisticsUtils.java From letv with Apache License 2.0 | 6 votes |
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); }
Example #24
Source File: AMapLocationTool.java From letv with Apache License 2.0 | 6 votes |
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; }
Example #25
Source File: JavaScriptinterface.java From letv with Apache License 2.0 | 6 votes |
@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()); }
Example #26
Source File: ShareLocationActivity.java From sealtalk-android with MIT License | 5 votes |
/** * 定位成功后回调函数 */ @Override public void onLocationChanged(AMapLocation aLocation) { if (mListener != null && aLocation != null) { mListener.onLocationChanged(aLocation);// 显示系统小蓝点 } }
Example #27
Source File: Utils.java From Android_Location_Demo with Apache License 2.0 | 5 votes |
/** * 根据定位结果返回定位信息的字符串 * @param loc * @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"); sb.append("速 度 : " + location.getSpeed() + "米/秒" + "\n"); sb.append("角 度 : " + location.getBearing() + "\n"); // 获取当前提供定位服务的卫星个数 sb.append("星 数 : " + location.getSatellites() + "\n"); sb.append("国 家 : " + location.getCountry() + "\n"); sb.append("省 : " + location.getProvince() + "\n"); sb.append("市 : " + location.getCity() + "\n"); sb.append("城市编码 : " + location.getCityCode() + "\n"); sb.append("区 : " + location.getDistrict() + "\n"); sb.append("区域 码 : " + location.getAdCode() + "\n"); sb.append("地 址 : " + location.getAddress() + "\n"); sb.append("兴趣点 : " + location.getPoiName() + "\n"); //定位完成的时间 sb.append("定位时间: " + formatUTC(location.getTime(), "yyyy-MM-dd HH:mm:ss") + "\n"); } else { //定位失败 sb.append("定位失败" + "\n"); sb.append("错误码:" + location.getErrorCode() + "\n"); sb.append("错误信息:" + location.getErrorInfo() + "\n"); sb.append("错误描述:" + location.getLocationDetail() + "\n"); } //定位之后的回调时间 sb.append("回调时间: " + formatUTC(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "\n"); return sb.toString(); }
Example #28
Source File: Location_Activity.java From Android_Location_Demo with Apache License 2.0 | 5 votes |
@Override public void onLocationChanged(AMapLocation loc) { if (null != loc) { //解析定位结果 String result = Utils.getLocationStr(loc); tvResult.setText(result); } else { tvResult.setText("定位失败,loc is null"); } }
Example #29
Source File: Util.java From RecordPath3D with Apache License 2.0 | 5 votes |
/** * 将AMapLocation List 转为LatLng list * @param list * @return */ public static List<LatLng> parseLatLngList(List<AMapLocation> list) { List<LatLng> traceList = new ArrayList<LatLng>(); if (list == null) { return traceList; } for (int i = 0; i < list.size(); i++) { AMapLocation loc = list.get(i); double lat = loc.getLatitude(); double lng = loc.getLongitude(); LatLng latlng = new LatLng(lat, lng); traceList.add(latlng); } return traceList; }
Example #30
Source File: LastLocation_Activity.java From Android_Location_Demo with Apache License 2.0 | 5 votes |
@Override public void onClick(View v) { if(v.getId() == R.id.bt_lastLoc){ AMapLocation location = locationClient.getLastKnownLocation(); String result = Utils.getLocationStr(location); tvReult.setText(result); } }