private void init() {
mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL;
mCurrentMarker = null;
mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(
mCurrentMode, true, null));
// 开启定位图层
mBaiduMap.setMyLocationEnabled(true);
// 定位初始化
mLocClient = new LocationClient(this);
mLocClient.registerLocationListener(myListener);
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true); // 打开gps
option.setCoorType("bd09ll"); // 设置坐标类型
option.setScanSpan(1000);
mLocClient.setLocOption(option);
mLocClient.start();
/*第一个*/
LatLng point1 = new LatLng(39.963175, 116.400244);
//构建Marker图标
BitmapDescriptor bitmap1 = BitmapDescriptorFactory
.fromResource(R.mipmap.site_car);
//构建MarkerOption,用于在地图上添加Marker
OverlayOptions option1 = new MarkerOptions()
.position(point1)
.icon(bitmap1);
//在地图上添加Marker,并显示
mBaiduMap.addOverlay(option1);
/*第二个*/
LatLng point2 = new LatLng(39.963355, 116.401253);
//构建Marker图标
BitmapDescriptor bitmap2 = BitmapDescriptorFactory
.fromResource(R.mipmap.site_worker);
//构建MarkerOption,用于在地图上添加Marker
OverlayOptions option2 = new MarkerOptions()
.position(point2)
.icon(bitmap2);
//在地图上添加Marker,并显示
mBaiduMap.addOverlay(option2);
mBaiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
InfoWindow mInfoWindow;
TextView location = new TextView(getApplicationContext());
location.setAlpha(0.5f);
location.setPadding(30, 20, 30, 50);
location.setText("位置" + marker.getPosition());
location.setBackgroundResource(R.mipmap.umeng_xp_cm_download_button_selected);
//将marker所在的经纬度的信息转化成屏幕上的坐标
final LatLng ll = marker.getPosition();
Point p = mBaiduMap.getProjection().toScreenLocation(ll);
p.y -= 120;
LatLng llInfo = mBaiduMap.getProjection().fromScreenLocation(p);
mInfoWindow = new InfoWindow(location, llInfo, 1);
mBaiduMap.showInfoWindow(mInfoWindow);
return false;
}
});百度地图API 点击地图提示信息
最新推荐文章于 2023-06-17 12:15:43 发布
本文介绍如何使用百度地图SDK实现定位功能并添加Marker。通过设置LocationClientOption配置GPS定位、坐标类型等参数来启动定位服务。同时展示了如何在地图上添加两个Marker,并为Marker设置点击监听事件以展示InfoWindow。
3714

被折叠的 条评论
为什么被折叠?



