Google Map(一)

今天学习了google map的简单开发,此篇博文主要内容是:在android手机上显示google map。 

下面就来完成上面所提及的功能:

1、首先要在AndroidManifest.xml中添加the standard Android library,在AndroidManifest.xml的application节点中添加如下内容 

 

<uses-library android:name="com.google.android.maps" /> 

 

另外还要开通网络权限,在manifest的child节点中添加如下

 

<uses-permission android:name="android.permission.INTERNET" />

 

 

2、打开res/layout/main.xml,在里面添加com.google.android.maps.MapView节点:

 

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="0JF2BOEcpjLIf3HVmXn28EL-ahyk_mJbHBICUeg"
/>

 

 

 

 

<!-- 这个apiKey是我申请的,各不一样,你们要用使用自己的apiKey --> 

 

3、我们要把自己写的Activity类实现MapActivity类。

 

public class googlemap1 extends MapActivity {

 

 

 

4、必须重写MapActivityisRouteDisplayed()方法

 

@Override
protected boolean isRouteDisplayed() {
          return false;
}

 

 

5、添加onCreate()回调方法

 

 

@Override 
public void onCreate(Bundle savedInstanceState) { 
	super.onCreate(savedInstanceState); 
	setContentView(R.layout.main); 
	MapView mapView = (MapView) findViewById(R.id.mapview); 
	mapView.setBuiltInZoomControls(true); //设置mapView显示用于缩放的工具条 } 
}

 

 到此我们就可以获得google map显示在手机屏幕上了,当然我们不仅仅是使用google map在手机上简单的显示而已,下面我们在地图上添加OverlayItem(地图上显示的标记)。详情请参见 (Google Map(二))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值