hai's profile★ Starfish^-^ ★ PhotosBlogLists Tools Help

Blog


    06/11/2009

    在Android中使用Map需要注意的技巧

    一、申请获得Map API的密钥

    申请APIkey的时候,类似命令如下:
    keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android

    生成页面:http://code.google.com/android/maps-api-signup.html

    二、Apikey放在正确的位置

    1、XML布局文件中

    <view android:id="@+id/mv"
       class="com.google.android.maps.MapView"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:apiKey="01Yu9W3X3vbpYT3x33chPXXX7U1Z6jy8WYZXNFA"
       />

    2、java中

            mMapView = new MapView(this, "01Yu9W3X3vbpYT3x33chPxxx7U1Z6jy8WYZXNFA");

    三、记得导入uses-library

    使用的时候需要在manifest中的application节点下加入

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

     

    四、需要给予一定的权限

    因为要使用GoogleMAP的service,所以需要
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

    如果需要GPS等应用,还需要

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

    五、Activity需要继承自MapActivity

    类似如下代码;

    package com.iceskysl.showmap;

    import com.google.android.maps.MapActivity;

    import android.os.Bundle;

    public class ShowMap extends MapActivity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
        }

        @Override
        protected boolean isRouteDisplayed() {
            // TODO Auto-generated method stub
            return false;
        }
    }

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://xinhai78.spaces.live.com/blog/cns!D593B15501500E8D!4396.trak
    Weblogs that reference this entry
    • None