Android-MapView.第一个简略的MapView

Android--MapView.第一个简单的MapView

 

 

 

 

1.新建一个类,继承MapActivity类,选择Google APIs

Android-MapView.第一个简略的MapView

 

 

2.在AndroidManifest.xml文件中添加map库和网络访问权限

Android-MapView.第一个简略的MapView

 

3.main.xml文件,此处的apiKey为你自己申请的key,

如何取得apiKey,请看http://blog.csdn.net/zlqqhs/article/details/8548439

 

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

    <com.google.android.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="0LohYR7LZtdkVKy3GnPMW_TOEC4I9zd1xAlwxAQ"
        android:clickable="true" />

</LinearLayout>


 

4.MapAcitivy代码:

 

package cn.mrzhu.map;

import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class HelloMapActivity extends MapActivity {
	MapView mapView;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //取出控件
        mapView = (MapView) findViewById(R.id.mapview);
        //设置缩放,点击地图时下方出现可控件缩放的控件
        mapView.setBuiltInZoomControls(true);
    }
    
	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}
}


 

5.新建Google APIs模拟器

Android-MapView.第一个简略的MapView