首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android学习心得(5)——GOOGLE MAP

2012-09-09 
Android学习心得(五)——GOOGLE MAPGOOGLE MAP API是Android的靓点之一,我们可以创建一个MapActivity的子类,

Android学习心得(五)——GOOGLE MAP
GOOGLE MAP API是Android的靓点之一,我们可以创建一个MapActivity的子类,将MapView显示于其上即可,可以用MapController来控制显示的坐标、地图模式和视野高度,处理起来非常简单。
完整代码如下:

public class MapTest extends MapActivity {private MapView mapView;private MapController mc;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.mapview);mapView = (MapView) findViewById(R.id.map);mapView.setTraffic(true);mc = mapView.getController();GeoPoint gp = new GeoPoint((int) (30.659259 * 1000000), (int) (104.065762 * 1000000)); //地理坐标mc.animateTo(gp);mc.setZoom(12);  }@Overrideprotected boolean isRouteDisplayed() {return false;}}

mapview.xml内容如下:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    ><com.google.android.maps.MapView android:id="@+id/map"    android:layout_width="fill_parent"     android:layout_height="fill_parent"    android:enabled="true"    android:clickable="true"    android:apiKey="0mHnPl2NS9XPKx6pKwJriV2Wj-mEHSh71yyX_SQ"    /></RelativeLayout>


注意:
1、你要申请一个自己的apiKey;
2、不要忘了设置互联网访问权限。

(作者:子轩,邮箱:zh1003@163.com)
[本节结束]
apiKey要填你自己的,则否就是空白的。 3 楼 huangbq 2010-05-31   按照你的步骤我成功的显示出google地图,不过我想更进一步实现放大和缩小功能,即在地图的布局xml中加上连个按钮:“放大”和“缩小”,怎么写布局xml和Activity的实现代码? 4 楼 zx012345 2010-05-31   huangbq 写道按照你的步骤我成功的显示出google地图,不过我想更进一步实现放大和缩小功能,即在地图的布局xml中加上连个按钮:“放大”和“缩小”,怎么写布局xml和Activity的实现代码?
你可以使用map中已有的,你也可以定义自己的,无非就是调用setZoom()方法,如:
mc.setZoom(12);
参数值的范围大概是1到20,具体你可以查一下,值变大就是放大,变小就是缩小。

热点排行