【Android】第3章(3)基本地图功能
分类:C#、Android; 日期:2016-02-04 3.2 示例2--基本地图功能 一、简介 1、地图 地图展示:普通地图(2D,3D)、卫星图和实时交通图。 地图操作:可通过接口或手势控制来实现地图的点击、双击、长按、缩放、平移、旋转、改变视角等操作。 2、地图类型 百
分类:C#、Android; 日期:2016-02-04
3.2 示例2--基本地图功能
一、简介
1、地图
地图展示:普通地图(2D,3D)、卫星图和实时交通图。
地图操作:可通过接口或手势控制来实现地图的点击、双击、长按、缩放、平移、旋转、改变视角等操作。
2、地图类型
百度地图Android SDK 3.6.1提供了两种类型的地图资源(普通矢量地图和卫星图,设置办法见demo04),如果不指定地图类型,默认为普通矢量地图。
此示例仅演示普通矢量图的基本用法。
3、本示例功能描述
该例子介绍如何构建一个基础的地图页面,并演示如何显示以自定义的经纬度坐标为中心点的百度地图。
简介:创建一张百度地图并管理地图的生命周期。
详述:
(1)创建一张最简单的百度地图;
(2)管理地图的生命周期,具体请参看代码部分的相关注释;
(3)可监听地图加载完成事件;
4、本示例运行截图
在x86模拟器中运行的效果如下:
二、设计步骤
1、添加Demo02BaseMap.cs文件
先在项目中添加一个SrcSdkDemos文件夹,然后在该文件夹下添加该文件。
<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;">namespace</span><span style="color: #000000;"> BdMapV371Demos.SrcSdkDemos { [Activity(Label </span>= <span style="color: #800000;">"</span><span style="color: #800000;">@string/demo_name_basemap</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;"> Demo02BaseMap : Activity { </span><span style="color: #0000ff;">PRivate</span><span style="color: #000000;"> TextureMapView mMapView; </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); mMapView </span>= <span style="color: #0000ff;">new</span> TextureMapView(<span style="color: #0000ff;">this</span><span style="color: #000000;">, </span><span style="color: #0000ff;">new</span> BaiduMapOptions().MapStatus(<span style="color: #0000ff;">new</span><span style="color: #000000;"> MapStatus.Builder() .Target(MainActivity.HeNanUniversity) .Build())); SetContentView(mMapView); } </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnPause() { </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnPause(); mMapView.OnPause(); } </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnResume() { </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnResume(); mMapView.OnResume(); } </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnDestroy() { </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnDestroy(); mMapView.OnDestroy(); } } }</span>
2、修改MainActivity.cs文件
在MainActivity.cs文件的demos字段定义中添加下面的代码。
<span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">readonly</span> DemoInfo<activity>[] demos =<span style="color: #000000;"> { …… </span><span style="color: #008000;">//</span><span style="color: #008000;">示例1--基本地图功能</span> <span style="color: #0000ff;">new</span> DemoInfo<activity><span style="color: #000000;">(Resource.String.demo_title_basemap, Resource.String.demo_desc_basemap, </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> Demo01BaseMap()), }</span></activity></activity>
运行,单击主界面中的【示例1】,观察结果。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

OnLeaks has now partnered with Android Headlines to provide a first look at the Galaxy S25 Ultra, a few days after a failed attempt to generate upwards of $4,000 from his X (formerly Twitter) followers. For context, the render images embedded below h

Alongside announcing two new smartphones, TCL has also announced a new Android tablet called the NXTPAPER 14, and its massive screen size is one of its selling points. The NXTPAPER 14 features version 3.0 of TCL's signature brand of matte LCD panels

The Vivo Y300 Pro just got fully revealed, and it's one of the slimmest mid-range Android phones with a large battery. To be exact, the smartphone is only 7.69 mm thick but features a 6,500 mAh battery. This is the same capacity as the recently launc

Samsung has not offered any hints yet about when it will update its Fan Edition (FE) smartphone series. As it stands, the Galaxy S23 FE remains the company's most recent edition, having been presented at the start of October 2023. However, plenty of

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

The Redmi Note 14 Pro Plus is now official as a direct successor to last year'sRedmi Note 13 Pro Plus(curr. $375 on Amazon). As expected, the Redmi Note 14 Pro Plus heads up the Redmi Note 14 series alongside theRedmi Note 14and Redmi Note 14 Pro. Li

OnePlus'sister brand iQOO has a 2023-4 product cycle that might be nearlyover; nevertheless, the brand has declared that it is not done with itsZ9series just yet. Its final, and possibly highest-end,Turbo+variant has just beenannouncedas predicted. T
