Big Bug Ban

兴趣 践行 创新

Archive for 十月, 2010

Android开发日志 MapView使用需要注意的部分

 

好像网上的都比较全了.我就只写写要注意的部分

第一. 新建AVD的时候一定要注意

需要创建一个含有Google Apis的AVD

如图所示

image

第二  在Android Manifest.xml中增加以下语句 增加map的支持

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.techest.schoolpaper">
    <application>
        <uses-library android:name="com.google.android.maps" />
         <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>

第三  你的Activity必须继承MapActivity

/*  Copyright 2010 princehaku
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *  Created on : 2010-10-18, 21:05:57
 *  Author     : princehaku
 */

package com.techest.schoolpaper;

import android.os.Bundle;
import android.view.View.OnTouchListener;
import com.google.android.maps.MapActivity;

/**
 *
 * @author princehaku
 */
public class MainActivity extends MapActivity{

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.mapview);
    }
        
    /**必须重载此方法
     *
     * @return
     */
    @Override
    protected boolean isRouteDisplayed() {
       return false;
    }


}

最后一个 就是那个XML

 
<view class = "com.google.android.maps.MapView"
    android:id = "@+id/my_map"
    android:enabled = "true"
    android:clickable = "true"
    android:longClickable= "true"
    android:apiKey="你申请到的key"
    android:layout_width="fill_parent"
    android:layout_height="380px"
    android:layout_alignTop="@+id/render_map"
    />


你申请到的key 那个地方填上你在http://code.google.com/intl/zh-CN/android/maps-api-signup.html申请到的key

这个key是更具你的证书和电脑hash一起计算出来的

使用命令行

keytool -list -keystore ~/.android/debug.keystore


可以得到一个hash 然后去上面那个网站申请就可以得到一个key

keytool这个工具可以在Java/bin目录下找到, 一般都存在于环境变量了 可以直接使用

Written by princehaku

十月 26th, 2010 at 6:35 下午