MapView

一、注册MapApis

http://code.google.com/intl/zh-CN/android/maps-api-signup.html

二、查询经度纬度或地址

http://code.google.com/intl/zh-CN/apis/maps/documentation/geocoding/index.html

三、代码

Activity代码:

public class Map3Activity extends MapActivity {

    private MapView mapview1=null;

    private MapController mapControl=null;

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        mapview1=(MapView)findViewById(R.id.mapview1);

        mapview1.setBuiltInZoomControls(true);

        mapview1.displayZoomControls(true);

        //给mapview定位经纬度

        mapControl=mapview1.getController();

        //设置缩放倍数

        mapControl.setZoom(20);

        double lat=24.5964035;

        double lng=118.10156260;

        GeoPoint geopoint=new GeoPoint((int) (lat*1E6),(int) (lng*1E6));

        mapControl.animateTo(geopoint);

        

    }

 

    @Override

    protected boolean isRouteDisplayed() {

       // TODO Auto-generated method stub

       return false;

    }

}

Main.xml代码:

<com.google.android.maps.MapView

                 android:layout_width="fill_parent"

                 android:layout_height="fill_parent"

                 android:apiKey="0pSP1qN-2q2tDLBn-t_X3vj5y1SvB1FOllBhRWg"

                 android:enabled="true"

                 android:id="@+id/mapview1"

        android:clickable="true"

                 />

Manifest.xml代码:

  <uses-sdkandroid:minSdkVersion="10"/>  

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

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

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

 <!-- 下面一行代码很重要 -->

    <applicationandroid:icon="@drawable/icon"android:label="@string/app_name">

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

        <activityandroid:name=".Map3Activity"

                  android:label="@string/app_name">

            <intent-filter>

                <actionandroid:name="android.intent.action.MAIN"/>

                <categoryandroid:name="android.intent.category.LAUNCHER"/>

            </intent-filter>

        </activity>

    </application>

 

posted @ 2011-08-29 23:15  rorshach  阅读(200)  评论(0编辑  收藏  举报