安卓开发的一些感触

安卓开发是一个纯正的mvc架构   使用百度地图的API显示地图

下面是我写的一个demo

主要使用了百度的安卓API  前面添加百度的东西可一参考百度地图官网 代码部分如下

布局文件的部分

<TableLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"/>
    <LinearLayout ><Button 
        android:id="@+id/dingwei"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="@string/dingwei"/>
    
    <Button 
        android:id="@+id/weixing"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/weixing"/>
    <Button 
        android:id="@+id/CloseWeixing"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/CloseWeixing"/>
        
    </LinearLayout>

    <com.baidu.mapapi.map.MapView
        android:id="@+id/bmapsView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true" />
 </TableLayout>
 
//主要JAVA部分
package com.myproject.mynewmap;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.map.MapController;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MyLocationOverlay;
import com.baidu.mapapi.map.LocationData;
import com.baidu.platform.comapi.basestruct.GeoPoint;
import android.view.*;

public class MainActivity extends Activity {
	BMapManager mBMapMan = null;
	MapView mMapView = null;
	
	//定位初始化
	
	
	Button testUpdateButton = null;
	
	EditText indexText = null;
	MyLocationOverlay myLocationOverlay = null;
	int index =0;
	LocationData locData = null;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mBMapMan=new BMapManager(getApplication());
		mBMapMan.init("A584651AB735E6141BAB303A842AB5DB51BBE753", null);  
		//注意:请在试用setContentView前初始化BMapManager对象,否则会报错
		setContentView(R.layout.activity_main);
		mMapView=(MapView)findViewById(R.id.bmapsView);
		mMapView.setBuiltInZoomControls(true);
		//设置启用内置的缩放控件
		MapController mMapController=mMapView.getController();
		// 得到mMapView的控制权,可以用它控制和驱动平移和缩放
		GeoPoint point =new GeoPoint((int)(27.990* 1E6),(int)(112.924* 1E6));
		//用给定的经纬度构造一个GeoPoint,单位是微度 (度 * 1E6)
		mMapController.setCenter(point);//设置地图中心点
		mMapController.setZoom(12);//设置地图zoom级别
		//mMapView.setSatellite(true);
		
		
		Button btnOpenWeiXing=(Button)findViewById(R.id.weixing);
		btnOpenWeiXing.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mMapView.setSatellite(true);
				
			}
		});
		
		
		Button btnCloseWeiXing=(Button)findViewById(R.id.CloseWeixing);
		btnCloseWeiXing.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mMapView.setSatellite(false);
				
			}
		});
	}

	@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() {
		// TODO Auto-generated method stub
		mMapView.destroy();
        if(mBMapMan!=null){
                mBMapMan.destroy();
                mBMapMan=null;
        }
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		mMapView.onPause();
        if(mBMapMan!=null){
                mBMapMan.stop();
        }
		super.onPause();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		 mMapView.onResume();
	        if(mBMapMan!=null){
	                mBMapMan.start();
	        }
		super.onResume();
	}

}


string部分以供参考

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">MyNewMap</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">土地资源管理系统</string>
    <string name="setSatellite">setSatellite</string>
    <string name="dingwei">开始定位</string>
    <string name="weixing">打开卫星地图</string>
    <string name="CloseWeixing">关闭卫星地图</string>

</resources>

但是地位部分还没实现 敬请期待…………


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值