基于高德sdk实现摩拜单车主界面,滑动地图获取地址信息
共享单车可以说是2016年至今,一个火的不要不要的项目,简单的界面,实用的功能。观察摩拜单车,ofo单车等几个项目会发现,基本上大同小异,项目的思路跟滴滴打车项目大同小异,都是基于Gps定位,实现查找出行工具的一种出行项目,区别在于滴滴找的车是四个轮子的,摩拜等共享单车则是找两个轮子的自行车。
个人吐槽,我不知道这种共享单车的项目为什么会这么受投资人的喜爱,动不动则上亿的融资进来。
个人分析优点:
1.共享单车在某种程度上来讲确是一个快速增加用户量的项目,而用户量对于数据纷飞的时代来说就是金钱
2.共享单车由于是这种押金的模式可以快速收回投入资本,虽然押金不是自己的,但是这种大量的资金流在投资人手里来说则有太多的赚钱方式了,但是两会后政府明显对这种资金控制力度加大,甚至来说为了防止资金去向不明,投资失败,政府会不允许公司动用这些资金
3.中国现在私家车越来越多,公路交通越来越堵,自行车在某种程度的短距离内能够有效缓解出行压力
4.中国环境污染严重,看上海越来越多的电动汽车就能看出,政府更倾向于环保的电动能源,而没有什么车比自行车更环保了,自行车在不赶时间的情况下,5公里内都是很方便的,那么一个人五公里,当这个人数基数变大时,是能够起到环保的作用的
有点跑题了,回到项目基于高德sdk实现滑图取点。先上图
在pos机上运行的,拖动地图,然后下面的edittext会显示marker所在地图上的地址信息。
准备:高德开发者平台申请账号并申请key,下载两个jar,AMap2DMap_4.2.0_AMapSearch_4.0.0_20170120.jar和
AMap_Location_V3.3.0_20170118.jar。
步骤分析:
1、显示地图
2、获取当前定位
3、将marker标记在当前定位点
4、将marker标记在屏幕中间保持不动
5、滑动地图获取marker所在经纬度,
6、将经纬度转换为地址信息显示
code如下:
//显示地图容器 1、mapView.onCreate(savedInstanceState);
//获取map
2、aMap = mapView.getMap();
//获取AMapLocationClient
3、mLocationClient = new AMapLocationClient(IApplication.getInstance());
//定位监听
4、mLocationClient.setLocationListener(mLocationListener);
//定位回调监听 private AMapLocationListener mLocationListener = new AMapLocationListener() { @Override public void onLocationChanged(AMapLocation aMapLocation) { if (aMapLocation != null) { if (aMapLocation.getErrorCode() == 0) { //可在其中解析amapLocation获取相应内容。 String address = aMapLocation.getAddress(); mLatitude = aMapLocation.getLatitude(); mLongitude = aMapLocation.getLongitude(); //当前位置设置为地图中心 setMapCenter(mLongitude, mLatitude); } else { //定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息 } } } };
5、//启动定位
mLocationClient.startLocation();
6、//地图显示到当前位置
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 18));
7、//marker固定在屏幕中间
marker.setPositionByPixels(IApplication.getWidth() / 2, IApplication.getHeight() / 2 - IApplication.getHeight() * 10 / 100);
8、//map设置视角监听
aMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener(){
@Override public void onCameraChange(CameraPosition cameraPosition) { } @Override public void onCameraChangeFinish(CameraPosition cameraPosition) {
//实时获取marker所在经纬度 LatLng mLatLng = marker.getPosition(); mLatitude = mLatLng.latitude; mLongitude = mLatLng.longitude;
LatLonPoint latLonPoint = new LatLonPoint(mLatitude, mLongitude);
getAddressByLatLonPoint(latLonPoint);
}})
9.//坐标转地址
private void getAddressByLatLonPoint(LatLonPoint latLonPoint) { GeocodeSearch geocodeSearch = new GeocodeSearch(MainActivity.this); RegeocodeQuery regeocodeQuery = new RegeocodeQuery(latLonPoint, 200, GeocodeSearch.AMAP); geocodeSearch.getFromLocationAsyn(regeocodeQuery); //监听逆地理编码结果 geocodeSearch.setOnGeocodeSearchListener(new MyOnGeocodeSearchListener() { @Override protected void myOnRegeocodeSearched(RegeocodeResult regeocodeResult, int backCode) { if (backCode == 1000) { et_startPosition.setText(""); RegeocodeAddress regeocodeAddress = regeocodeResult.getRegeocodeAddress(); String formatAddress = regeocodeAddress.getFormatAddress(); ToastUtil.getInstacne().shortShow(formatAddress); et_startPosition.setText(formatAddress); } else { LogUtil.getInstance().i(getClassName(), getResources().getString(R.string.regeocodeResult_error)); } } }); }