2 zhangzhilai8 zhangzhilai8 于 2013.07.12 13:41 提问

android百度地图官网Hello world运行不了

Main.java代码
package com.example.baidu;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

import android.app.Activity;

import android.content.res.Configuration;

import android.os.Bundle;

import android.view.Menu;

import android.widget.FrameLayout;

import android.widget.Toast;

import com.baidu.mapapi.BMapManager;

import com.baidu.mapapi.map.MKMapViewListener;

import com.baidu.mapapi.map.MapController;

import com.baidu.mapapi.map.MapPoi;

import com.baidu.mapapi.map.MapView;

import com.baidu.platform.comapi.basestruct.GeoPoint;

public class Main extends Activity {

BMapManager mBMapMan = null;  
MapView mMapView = null; 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);  
    mBMapMan=new BMapManager(getApplication()); 



    mBMapMan.init("F77B82897CD6193729368255C1771CA1BB1348D0", null);    
    //注意:请在试用setContentView前初始化BMapManager对象,否则会报错  
    setContentView(R.layout.main);  
    mMapView=(MapView)findViewById(R.id.bmapsView);  
    mMapView.setBuiltInZoomControls(true);  
    //设置启用内置的缩放控件  
    MapController mMapController=mMapView.getController();  
    // 得到mMapView的控制权,可以用它控制和驱动平移和缩放  
    GeoPoint point =new GeoPoint((int)(39.915* 1E6),(int)(116.404* 1E6));  
    //用给定的经纬度构造一个GeoPoint,单位是微度 (度 * 1E6)  
    mMapController.setCenter(point);//设置地图中心点  
    mMapController.setZoom(12);//设置地图zoom级别 
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}



@Override  
protected void onDestroy(){  
        mMapView.destroy();  
        if(mBMapMan!=null){  
                mBMapMan.destroy();  
                mBMapMan=null;  
        }  
        super.onDestroy();  
}  
@Override  
protected void onPause(){  
        mMapView.onPause();  
        if(mBMapMan!=null){  
               mBMapMan.stop();  
        }  
        super.onPause();  
}  
@Override  
protected void onResume(){  
        mMapView.onResume();  
        if(mBMapMan!=null){  
                mBMapMan.start();  
        }  
       super.onResume();  
}  

}

AndroidManifest.xml代码

<?xml version="1.0" encoding="utf-8"?>
package="com.example.baidu"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<supports-screens android:largeScreens="true"  
        android:normalScreens="true"  
        android:smallScreens="true"  
        android:resizeable="true"  
        android:anyDensity="true"/>  













<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity

        android:name="com.example.baidu.Main"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

main.xml代码
<?xml version="1.0" encoding="utf-8"?>

android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

android:layout_height="wrap_content"
android:text="hello world" />

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />

1个回答

suxiaodong512228
suxiaodong512228   2013.07.19 13:14
已采纳

在AndroidManifest中添加这个,

<service
        android:name="com.baidu.location.f"
        android:enabled="true"
        android:process=":remote" >
    </service>
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!