Google map的Andriod方法

(1) 首先需要装Google API,而不是Andriod API...Google API包含了后者

(2)XML配置文件加入类似如下:

 

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

      package="ustc.googlemap"

      android:versionCode="1"

      android:versionName="1.0">

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

        <activity android:name=".googlemap"

                  android:label="@string/app_name">

            <intent-filter>

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

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

            </intent-filter>

        </activity>

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

 

    </application>

    <uses-sdk android:minSdkVersion="7" />

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

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

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

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

</manifest> 

 

 

(3)java代码:

package ustc.googlemap;

import android.app.Activity;

import android.content.Context;

import android.location.Location;

import android.location.LocationManager;

import android.os.Bundle;

import com.google.android.maps.GeoPoint;

import com.google.android.maps.MapActivity;

import com.google.android.maps.MapController;

import com.google.android.maps.MapView; 

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.TextView;

/*

 * 

 *(1)D:/Program Files/android-sdk-windows/tools>keytool -list -alias androiddebugkey -keystore "C:/Documents and Settings/yangtang/.android/debug.keystore" -storepass android -keypass android  

 *(2)得到结果:androiddebugkey, 2010-12-4, PrivateKeyEntry,

 *   认证指纹 (MD5): F4:97:88:B8:8F:DD:B6:89:FB:8F:7A:9B:33:81:49:B6

 * (3)打开http://code.google.com/intl/zh-CN/android/maps-api-signup.html

 

填入你的认证指纹(MD5)即可获得apiKey了,结果显示如下:

         感谢您注册 Android 地图 API 密钥!

 

            本机的密钥是:

    0Zc0jRGdC90eXHLc_3Se74PxeRbBO4ErYF9P_fg

 */

public class googlemap extends MapActivity{

private MapView mapView;

private MapController mapController;

 

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        mapView = (MapView)findViewById(R.id.mapview);

mapController = mapView.getController(); 

Double lng = 126.676530486 * 1E6;

Double lat = 45.7698895661 * 1E6;

GeoPoint point = new GeoPoint(  lat.intValue(),lng.intValue());

        mapController.setCenter(point);//显示中心

mapController.setZoom(9);//放大层级

mapController.animateTo(point);//动画到显示中心

mapView.setSatellite(true);//是否为卫星模式

final Button zoomIn = (Button) findViewById(R.id.buttonZoomIn); 

zoomIn.setOnClickListener(new Button.OnClickListener()

{ public void onClick(View v)

{ mapController.zoomIn(); }});

final Button zoomOut = (Button) findViewById(R.id.buttonZoomOut);

zoomOut.setOnClickListener(new Button.OnClickListener() 

{ public void onClick(View v)

{ mapController.zoomOut(); }});

        final Button gpsButton = (Button) findViewById(R.id.gpsButton);

        gpsButton.setOnClickListener(new Button.OnClickListener()

        { public void onClick(View v){ LoadCoords(); }}); 

    }

 

    public void LoadCoords(){

     TextView latText = (TextView) findViewById(R.id.latText);

     TextView lngText = (TextView) findViewById(R.id.lngText);

     String serviceString = Context.LOCATION_SERVICE;

     LocationManager locationManager = (LocationManager)getSystemService(serviceString);

     String provider = LocationManager.GPS_PROVIDER;

     Location location = locationManager.getLastKnownLocation(provider);

     Double latPoint = location.getLatitude();

     Double lngPoint = location.getLongitude();//myManager.getCurrentLocation("gps").getLongitude();

     latText.setText(latPoint.toString()); 

        lngText.setText(lngPoint.toString()); }    

    protected boolean isRouteDisplayed() {

// TODO Auto-generated method stub

return false;

}

 

}

 

(4)===main.xml====

 

 

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   

android:orientation="vertical"    

android:layout_width="fill_parent"   

android:layout_height="fill_parent"   

>

 

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:stretchColumns="1"

android:layout_height="wrap_content">

<TableRow  > 

<Button android:id="@+id/buttonZoomIn" style="?android:attr/buttonStyleSmall" android:text="+" android:layout_width="wrap_content" android:layout_height="wrap_content" /><Button android:id="@+id/gpsButton"  android:layout_column="1" 

android:layout_height="wrap_content" android:text="定位" android:layout_width="wrap_content"/>

<Button android:id="@+id/buttonZoomOut" style="?android:attr/buttonStyleSmall" android:text="-" android:layout_alignBottom="@+id/myMap" android:layout_width="wrap_content" android:layout_height="wrap_content" />

</TableRow>

</TableLayout>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:stretchColumns="1"

android:layout_height="wrap_content">

<TableRow>

   <TextView android:id="@+id/latLabel" android:layout_width="wrap_content"

  android:layout_height="wrap_content" android:text="Latitude: " />

  <TextView    android:id="@+id/latText" android:layout_width="wrap_content" 

   android:layout_height="wrap_content" /> 

     <TextView android:id="@+id/lngLabel" android:layout_width="wrap_content" 

     android:layout_height="wrap_content" android:text="Longitude: " />

     <TextView android:id="@+id/lngText" android:layout_width="wrap_content" 

      android:layout_height="wrap_content" /> 

</TableRow>

</TableLayout>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:stretchColumns="1"

>

<TableRow>

    <com.google.android.maps.MapView

android:id="@+id/mapview"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:enabled="true"

android:clickable="true"

 android:apiKey="0Zc0jRGdC90eXHLc_3Se74PxeRbBO4ErYF9P_fg"/>

 

</TableRow>

</TableLayout> 

</LinearLayout>

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值