BaiduMap---百度地图官方Demo之多地图展示(在一个Activity中创建多个地图展示)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="5dp"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <fragment
            android:id="@+id/map1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginRight="5dp"
            android:layout_weight="1"
            class="com.baidu.mapapi.map.SupportMapFragment" />

        <fragment
            android:id="@+id/map2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            class="com.baidu.mapapi.map.SupportMapFragment" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <fragment
            android:id="@+id/map3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginRight="5dp"
            android:layout_weight="1"
            class="com.baidu.mapapi.map.SupportMapFragment" />

        <fragment
            android:id="@+id/map4"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            class="com.baidu.mapapi.map.SupportMapFragment" />
    </LinearLayout>

</LinearLayout>





/**
 * 在一个Activity中创建多个地图展示
 */
public class MultiMapViewDemo extends FragmentActivity {

    private static final LatLng GEO_BEIJING = new LatLng(39.945, 116.404);
    private static final LatLng GEO_SHANGHAI = new LatLng(31.227, 121.481);
    private static final LatLng GEO_GUANGZHOU = new LatLng(23.155, 113.264);
    private static final LatLng GEO_SHENGZHENG = new LatLng(22.560, 114.064);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_multimap);
        initMap();
    }

    /**
     * 初始化Map
     */
    private void initMap() {
        /**
         * MapStatusUpdate:描述地图状态将要发生的变化
         * newLatLng(LatLng latLng):设置地图新中心点
         * */
        MapStatusUpdate u1 = MapStatusUpdateFactory.newLatLng(GEO_BEIJING);
        SupportMapFragment map1 = (SupportMapFragment) (getSupportFragmentManager()
                .findFragmentById(R.id.map1));
        /**
         * getBaiduMap():获取百度地图控制器,当执行完 onCreateView函数之后调用,否则返回 null.
         * BaiduMap.setMapStatus(MapStatusUpdate update):改变地图状态
         * */
        map1.getBaiduMap().setMapStatus(u1);

        MapStatusUpdate u2 = MapStatusUpdateFactory.newLatLng(GEO_SHANGHAI);
        SupportMapFragment map2 = (SupportMapFragment) (getSupportFragmentManager()
                .findFragmentById(R.id.map2));
        map2.getBaiduMap().setMapStatus(u2);

        MapStatusUpdate u3 = MapStatusUpdateFactory.newLatLng(GEO_GUANGZHOU);
        SupportMapFragment map3 = (SupportMapFragment) (getSupportFragmentManager()
                .findFragmentById(R.id.map3));
        map3.getBaiduMap().setMapStatus(u3);

        MapStatusUpdate u4 = MapStatusUpdateFactory.newLatLng(GEO_SHENGZHENG);
        SupportMapFragment map4 = (SupportMapFragment) (getSupportFragmentManager()
                .findFragmentById(R.id.map4));
        map4.getBaiduMap().setMapStatus(u4);
    }

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值