Heim > php教程 > php手册 > 【Android】第3章(6)示例5--多地图展示

【Android】第3章(6)示例5--多地图展示

WBOY
Freigeben: 2016-07-06 13:30:24
Original
954 Leute haben es durchsucht

分类:C#、Android、VS2015、百度地图应用; 创建日期:2016-02-04 3.5 示例5--多地图展示 一、简介 地图控件自v2.3.5版本起,支持多实例,即开发者可以在一个页面中建立多个地图对象,并且针对这些对象分别操作且不会产生相互干扰。 文件名:Demo04MultiMap

分类:C#、Android、VS2015、百度地图应用; 创建日期:2016-02-04

3.5 示例5--多地图展示

一、简介

地图控件自v2.3.5版本起,支持多实例,即开发者可以在一个页面中建立多个地图对象,并且针对这些对象分别操作且不会产生相互干扰。

文件名:Demo04MultiMapView.cs

简介:介绍多MapView的使用

详述:在一个界面内,同时建立四个TextureMapView控件;

二、示例

1、运行截图

在x86模拟器中的运行效果如下:

 

在上一节例子的基础上,只需要再增加下面的步骤即可。

2、添加demo05_multimap.axml文件

在layout文件夹下添加该文件,将其改为下面的代码:

 

<?xml version=<span style="color: #800000;">"<span style="color: #800000;">1.0</span><span style="color: #800000;">"</span> encoding=<span style="color: #800000;">"</span><span style="color: #800000;">utf-8</span><span style="color: #800000;">"</span>?>
<linearlayout xmlns:android="<span" style="color: #800000;">"<span style="color: #800000;">http://schemas.android.com/apk/res/android</span><span style="color: #800000;">"</span><span style="color: #000000;">
    xmlns:map</span>=<span style="color: #800000;">"</span><span style="color: #800000;">http://schemas.android.com/apk/res-auto</span><span style="color: #800000;">"</span><span style="color: #000000;">
    android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">match_parent</span><span style="color: #800000;">"</span><span style="color: #000000;">
    android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">match_parent</span><span style="color: #800000;">"</span><span style="color: #000000;">
    android:orientation</span>=<span style="color: #800000;">"</span><span style="color: #800000;">vertical</span><span style="color: #800000;">"</span> >

    LinearLayout
        android:layout_width=<span style="color: #800000;">"</span><span style="color: #800000;">match_parent</span><span style="color: #800000;">"</span><span style="color: #000000;">
        android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">match_parent</span><span style="color: #800000;">"</span><span style="color: #000000;">
        android:layout_marginBottom</span>=<span style="color: #800000;">"</span><span style="color: #800000;">5dp</span><span style="color: #800000;">"</span><span style="color: #000000;">
        android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span><span style="color: #000000;">
        android:orientation</span>=<span style="color: #800000;">"</span><span style="color: #800000;">horizontal</span><span style="color: #800000;">"</span> >

        fragment
            android:id=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/map1</span><span style="color: #800000;">"</span><span style="color: #000000;">
            android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">match_parent</span><span style="color: #800000;">"</span><span style="color: #000000;">
            android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">match_parent</span><span style="color: #800000;">"</span><span style="color: #000000;">
            android:layout_marginRight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">5dp</span><span style="color: #800000;">"</span><span style="color: #000000;">
            android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span>
            <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">com.baidu.mapapi.map.TextureMapFragment</span><span style="color: #800000;">"</span> />

        fragment
            android:id=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/map2</span><span style="color: #800000;">"</span><span style="color: #000000;">
            android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">match_parent</span><span style="color: #800000;">"</span><span style="color: #000000;">
            android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">match_parent</span><span style="color: #800000;">"</span><span style="color: #000000;">
            android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span>
            <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">com.baidu.mapapi.map.TextureMapFragment</span><span style="color: #800000;">"</span> />
    </linearlayout>

    LinearLayout
        android:layout_width=<span style="color: #800000;">"</span><span style="color: #800000;">match_parent</span><span style="color: #800000;">"</span><span style="color: #000000;">
        android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">match_parent</span><span style="color: #800000;">"</span><span style="color: #000000;">
        android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span><span style="color: #000000;">
        android:orientation</span>=<span style="color: #800000;">"</span><span style="color: #800000;">horizontal</span><span style="color: #800000;">"</span> >

        fragment
            android:id=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/map3</span><span style="color: #800000;">"</span><span style="color: #000000;">
            android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">match_parent</span><span style="color: #800000;">"</span><span style="color: #000000;">
            android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">match_parent</span><span style="color: #800000;">"</span><span style="color: #000000;">
            android:layout_marginRight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">5dp</span><span style="color: #800000;">"</span><span style="color: #000000;">
            android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span>
            <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">com.baidu.mapapi.map.TextureMapFragment</span><span style="color: #800000;">"</span> />

        fragment
            android:id=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/map4</span><span style="color: #800000;">"</span><span style="color: #000000;">
            android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">match_parent</span><span style="color: #800000;">"</span><span style="color: #000000;">
            android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">match_parent</span><span style="color: #800000;">"</span><span style="color: #000000;">
            android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span>
            <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">com.baidu.mapapi.map.TextureMapFragment</span><span style="color: #800000;">"</span> />
    

Nach dem Login kopieren

 

3、添加Demo05MultiMapView.cs文件

在SdkDemos文件夹下添加该文件,然后将其内容改为下面的代码:

 

<span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.App;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.Content.PM;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.OS;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Com.Baidu.Mapapi.Map;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Com.Baidu.Mapapi.Model;

</span><span style="color: #0000ff;">namespace</span><span style="color: #000000;"> BdMapV371Demos.SrcSdkDemos
{
    </span><span style="color: #808080;">///</span> <span style="color: #808080;"><summary></summary></span>
    <span style="color: #808080;">///</span><span style="color: #008000;"> 在一个Activity中展示多个地图
    </span><span style="color: #808080;">///</span> <span style="color: #808080;"></span>
    [Activity(Label = <span style="color: #800000;">"</span><span style="color: #800000;">@string/demo_name_multimap</span><span style="color: #800000;">"</span><span style="color: #000000;">,
        ConfigurationChanges </span>= ConfigChanges.Orientation |<span style="color: #000000;"> ConfigChanges.KeyboardHidden,
        ScreenOrientation </span>=<span style="color: #000000;"> ScreenOrientation.Sensor)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> Demo05MutiMapView : Activity
    {
        </span><span style="color: #0000ff;">PRivate</span> <span style="color: #0000ff;">readonly</span> LatLng Geo_BeiJing = <span style="color: #0000ff;">new</span> LatLng(<span style="color: #800080;">39.945</span>, <span style="color: #800080;">116.404</span><span style="color: #000000;">);
        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">readonly</span> LatLng Geo_ShangHai = <span style="color: #0000ff;">new</span> LatLng(<span style="color: #800080;">31.227</span>, <span style="color: #800080;">121.481</span><span style="color: #000000;">);
        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">readonly</span> LatLng Geo_GuangZhou = <span style="color: #0000ff;">new</span> LatLng(<span style="color: #800080;">23.155</span>, <span style="color: #800080;">113.264</span><span style="color: #000000;">);
        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">readonly</span> LatLng Geo_ShenZhen = <span style="color: #0000ff;">new</span> LatLng(<span style="color: #800080;">22.560</span>, <span style="color: #800080;">114.064</span><span style="color: #000000;">);

        </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnCreate(Bundle savedInstanceState)
        {
            </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.demo05_multimap);
            InitMap();
        }

        </span><span style="color: #808080;">///</span> <span style="color: #808080;"><summary></summary></span>
        <span style="color: #808080;">///</span><span style="color: #008000;"> 初始化Map
        </span><span style="color: #808080;">///</span> <span style="color: #808080;"></span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> InitMap()
        {
            MapStatusUpdate u1 </span>=<span style="color: #000000;"> MapStatusUpdateFactory.NewLatLng(Geo_BeiJing);
            TextureMapFragment map1 </span>= FragmentManager.FindFragmentById<texturemapfragment><span style="color: #000000;">(Resource.Id.map1);
            map1.BaiduMap.SetMapStatus(u1);

            MapStatusUpdate u2 </span>=<span style="color: #000000;"> MapStatusUpdateFactory.NewLatLng(Geo_ShangHai);
            TextureMapFragment map2 </span>= FragmentManager.FindFragmentById<texturemapfragment><span style="color: #000000;">(Resource.Id.map2);
            map2.BaiduMap.SetMapStatus(u2);

            MapStatusUpdate u3 </span>=<span style="color: #000000;"> MapStatusUpdateFactory.NewLatLng(Geo_GuangZhou);
            TextureMapFragment map3 </span>= FragmentManager.FindFragmentById<texturemapfragment><span style="color: #000000;">(Resource.Id.map3);
            map3.BaiduMap.SetMapStatus(u3);

            MapStatusUpdate u4 </span>=<span style="color: #000000;"> MapStatusUpdateFactory.NewLatLng(Geo_ShenZhen);
            TextureMapFragment map4 </span>= FragmentManager.FindFragmentById<texturemapfragment><span style="color: #000000;">(Resource.Id.map4);
            map4.BaiduMap.SetMapStatus(u4);
        }
    }
}</span></texturemapfragment></texturemapfragment></texturemapfragment></texturemapfragment>
Nach dem Login kopieren

 

4、修改MainActivity.cs文件

在MainActivity.cs文件的demos字段定义中添加下面的代码。

<span style="color: #008000;">          //</span><span style="color: #008000;">示例5--多地图展示</span>
            <span style="color: #0000ff;">new</span> DemoInfo<activity><span style="color: #000000;">(Resource.String.demo_title_multimap,
                Resource.String.demo_desc_multimap,
                </span><span style="color: #0000ff;">new</span> Demo05MutiMapView()),</activity>
Nach dem Login kopieren

运行观察结果。


Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage