基本的地图服务包括三项功能:
- 让地图显示某个经纬度位置;
- 获取地图上某个点的经纬度;
- 在地图上标注出某个位置。
要让地图显示某个经纬度位置,步骤是:获取BaiduMap对象、设置位置、动画显示。
代码如下:
double longitude = Double.parseDouble(etLongitude.getText().toString());
double latitude = Double.parseDouble(etLatitude.getText().toString());
BaiduMap map = mMapView.getMap(); // 获取BaiduMap对象
map.setMyLocationEnabled(true);
// 设置当前位置
MyLocationData.Builder builder = new MyLocationData.Builder();
MyLocationData location = builder.accuracy(10).direction(100).longitude(longitude).latitude(latitude).build();
map.setMyLocationData(location);
// 动画显示
LatLng ll = new LatLng(location.latitude, location.longitude);
MapStatus.Builder statusBuilder = new MapStatus.Builder();
statusBuilder.target(ll).zoo