高德地图定位、画线 基础功能
2018-03-15 17:24
381 查看
1.先根据官网介绍下载相应的SDK包。
**注意,从坐标拾取系统上拾取的坐标,在使用时需要把经纬度反过来填写!!!
(拾取的是(10,20),设置时应该为(20,10))才能显示正确的位置**
a:定位设置
//三角箭头跟随手机方向转动
//初始化定位蓝点样式类
MyLocationStyle myLocationStyle = new MyLocationStyle();
// myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);
// 连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。
// (1秒1次定位)如果不设置myLocationType,默认也会执行此种模式。
//设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。
myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);
myLocationStyle.interval(10000);//持续定位,间隔10s
//设置定位蓝点的Style
aMap.setMyLocationStyle(myLocationStyle);
//设置默认定位按钮是否显示,自行设置。(true:地图上显示定位按钮,点击后自动定位当前位置)
aMap.getUiSettings().setMyLocationButtonEnabled(true);
myLocationStyle.showMyLocation(true);
//设置为true表示启动显示定位蓝点,false表示隐藏定位蓝点并不进行定位,默认是false。
aMap.setMyLocationEnabled(true);b:显示地图(可修改默认显示位置)
布局里面放置地图控件:
<com.amap.api.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>private MapView mapView; //地图控件
private AMap aMap;//地图控制器对象
mapView = (MapView) findViewById(R.id.map);
// a1.此方法须覆写,虚拟机需要在很多情况下保存地图绘制的当前状态。
mapView.onCreate(savedInstanceState);
//a2.初始化地图控制器对象(地图可以显示了,默认显示北京)
if (aMap == null) {
aMap = mapView.getMap();
}
//--------------------
//修改默认显示位置
LatLng latLng = new LatLng(30.489444,114.417544);//构造一个位置
//参数1:坐标点,参数2: 地图放大倍数
c:设置覆盖物(给一个坐标点设置图标)
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(10, 30), 19));
MarkerOptions options = new MarkerOptions();
options.position(new LatLng(10, 30));//指定地点
options.title("指定位置");//点击图标会显示此标题
options.visible(true);
options.draggable(true);//marker可以拖动
//maker 图标
BitmapDescriptor bp = BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stop));
options.icon(bp);
aMap.addMarker(options);
d:在地图上画图形
画线(根据坐标点画折现)
List<LatLng> latLngs = new ArrayList<>();
latLngs.add(new LatLng(30.489444,114.417544));
latLngs.add(new LatLng(30.49878,114.417472));
latLngs.add(new LatLng(30.492307,114.436947));
latLngs.add(new LatLng(30.485772,114.427461));
Polyline line = aMap.addPolyline(new PolylineOptions().addAll(latLngs).width(20).color(Color.argb(255, 1, 1, 1)));
line.setVisible(true);
画圆:
**注意,从坐标拾取系统上拾取的坐标,在使用时需要把经纬度反过来填写!!!
(拾取的是(10,20),设置时应该为(20,10))才能显示正确的位置**
a:定位设置
//三角箭头跟随手机方向转动
//初始化定位蓝点样式类
MyLocationStyle myLocationStyle = new MyLocationStyle();
// myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);
// 连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。
// (1秒1次定位)如果不设置myLocationType,默认也会执行此种模式。
//设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。
myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);
myLocationStyle.interval(10000);//持续定位,间隔10s
//设置定位蓝点的Style
aMap.setMyLocationStyle(myLocationStyle);
//设置默认定位按钮是否显示,自行设置。(true:地图上显示定位按钮,点击后自动定位当前位置)
aMap.getUiSettings().setMyLocationButtonEnabled(true);
myLocationStyle.showMyLocation(true);
//设置为true表示启动显示定位蓝点,false表示隐藏定位蓝点并不进行定位,默认是false。
aMap.setMyLocationEnabled(true);b:显示地图(可修改默认显示位置)
布局里面放置地图控件:
<com.amap.api.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>private MapView mapView; //地图控件
private AMap aMap;//地图控制器对象
mapView = (MapView) findViewById(R.id.map);
// a1.此方法须覆写,虚拟机需要在很多情况下保存地图绘制的当前状态。
mapView.onCreate(savedInstanceState);
//a2.初始化地图控制器对象(地图可以显示了,默认显示北京)
if (aMap == null) {
aMap = mapView.getMap();
}
//--------------------
//修改默认显示位置
LatLng latLng = new LatLng(30.489444,114.417544);//构造一个位置
//参数1:坐标点,参数2: 地图放大倍数
//此时显示指定位置aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,15));
c:设置覆盖物(给一个坐标点设置图标)
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(10, 30), 19));
MarkerOptions options = new MarkerOptions();
options.position(new LatLng(10, 30));//指定地点
options.title("指定位置");//点击图标会显示此标题
options.visible(true);
options.draggable(true);//marker可以拖动
//maker 图标
BitmapDescriptor bp = BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stop));
options.icon(bp);
aMap.addMarker(options);
d:在地图上画图形
画线(根据坐标点画折现)
List<LatLng> latLngs = new ArrayList<>();
latLngs.add(new LatLng(30.489444,114.417544));
latLngs.add(new LatLng(30.49878,114.417472));
latLngs.add(new LatLng(30.492307,114.436947));
latLngs.add(new LatLng(30.485772,114.427461));
Polyline line = aMap.addPolyline(new PolylineOptions().addAll(latLngs).width(20).color(Color.argb(255, 1, 1, 1)));
line.setVisible(true);
画圆:
LatLng latLng = new LatLng(30.489444,114.417544);//圆心点 Circle circle = aMap.addCircle(new CircleOptions() .center(latLng) .radius(1000)//半径 .fillColor(Color.argb(50,1, 1, 1))//填充颜色 .strokeColor(Color.RED)//边线颜色 .strokeWidth(20));//边线宽
相关文章推荐
- ios高德地图提醒打开定位功能
- 高德地图定位功能
- 高德地图定位功能在Android上的集成
- 高德地图基础功能使用心得
- Android之高德地图定位SDK集成及地图功能实现
- 高德地图集成之基础定位
- 高德地图定位功能(笔记)
- 高德地图基础功能使用心得
- 高德地图定位和附近功能
- Android中高德地图定位功能的实现
- android中高德地图定位功能并且获取定位的城市
- 高德地图返回当前定位位置功能
- 高德地图自动导航,定位功能
- 手把手教你实现百度基础地图+定位功能+设置中心点+添加Marker
- 高德地图定位功能
- 关于百度地图的基础地图和定位功能
- 手把手教你高德基础地图+定位+设置Marker实现
- Android 高德地图定位功能的实现步骤
- Android之高德地图定位SDK集成及地图功能实现
- 高德基础地图+定位+设置Marker实现