1、安装Google Play services SDK

打开Android SDK Manager,安装和更新Extras下的Google Play services即可。

2、安装Google Play Store和Google Play services

见附件中的com.android.vending.apk和com.google.android.gms.apk。

3、获取API Key

请参考:Google Map Android API V2中API Key的生成

4、修改AndroidManifest.xml

1)在<application>元素中加入子标签:

<meta-data            android:name="com.google.android.maps.v2.API_KEY"            android:value="AIzaSyAhyvAAt3rdR8ATIH2VKlLzjhb9ICDy3UM" />

将其中的android:value换成自己申请的API Key。

2)加入许可信息

<permission        android:name="com.example.demo.permission.MAPS_RECEIVE"        android:protectionLevel="signature" />    <uses-permission android:name="com.example.demo.permission.MAPS_RECEIVE" />

将其中的com.example.demo换成自己的包名。

3)加入其它许可设置

<uses-permission android:name="android.permission.INTERNET" />    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

4)加入OpenGL ES V2特性的支持

<uses-feature        android:glEsVersion="0x00020000"        android:required="true" />

5、加载Google Play services类库

在Eclipse里选择:File > Import > Android > Existing Android Code Into Workspace,然后点击Next,找到路径下的/Users/jsntghf/Projects/adt-bundle-mac-x86_64-20130219/sdk/extras/google/google_play_services/libproject/google-play-services_lib,最后点击Finish。

6、添加对Google Play services类库的引用

在项目上右键,选择Properties,左边选择Android,然后在下面的Library里添加刚才的google-play-services_lib。

7、显示地图

1)布局文件

<?xml version="1.0" encoding="utf-8"?><fragment xmlns:android="http://schemas.android.com/apk/res/android"  android:id="@+id/mapview"  android:layout_width="match_parent"  android:layout_height="match_parent"  class="com.google.android.gms.maps.SupportMapFragment"/>

2)MainActivity.java

package com.example.demo;import com.google.android.gms.common.ConnectionResult;import com.google.android.gms.common.GooglePlayServicesUtil;import com.google.android.gms.maps.CameraUpdateFactory;import com.google.android.gms.maps.GoogleMap;import com.google.android.gms.maps.SupportMapFragment;import com.google.android.gms.maps.model.BitmapDescriptorFactory;import com.google.android.gms.maps.model.LatLng;import com.google.android.gms.maps.model.MarkerOptions;import android.os.Bundle;import android.app.Activity;import android.app.Dialog;import android.support.v4.app.FragmentActivity;import android.view.Menu;public class MainActivity extends FragmentActivity {private GoogleMap googleMap;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());if (status != ConnectionResult.SUCCESS) {int requestCode = 10;Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this,requestCode);dialog.show();} else {SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapview);googleMap = fm.getMap();LatLng sfLatLng = new LatLng(-43.507227, 172.72233);googleMap.moveCamera(CameraUpdateFactory.newLatLng(sfLatLng));if (googleMap != null) {googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);googleMap.getUiSettings().setCompassEnabled(true);googleMap.getUiSettings().setZoomControlsEnabled(true);googleMap.getUiSettings().setMyLocationButtonEnabled(true);googleMap.addMarker(new MarkerOptions() .position(sfLatLng) .title("New Brighton") .snippet("New Brighton") .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sfLatLng, 15));googleMap.animateCamera(CameraUpdateFactory.zoomIn());googleMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2, null);}}}@Overridepublic 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;}}

效果图:


更多相关文章

  1. Android点击button触发Toast事件,弹出一个小小的消息框,几秒钟之
  2. LinearLayout和RelativeLayout的属性差异
  3. 存储容量检测 注意构建StatFs对象的参数合法性
  4. 一个切换的Widget
  5. Android(安卓)EditText 密码隐藏或可见
  6. 据说年薪30万的Android程序员必须知道事
  7. linux android 下源码编译问题总结(一)
  8. ScrollView can host only one direct child
  9. Android之WebView控件简单使用总结

随机推荐

  1. Android(安卓)系统广播机制
  2. android中自定义控件
  3. Android获取WIFI状态下的IP地址以及MAC地
  4. android web services
  5. Android:dimen尺寸资源文件的使用
  6. SeekBar 和 RatingBar
  7. Android2.2 API 中文文档系列(2) —— Edit
  8. 2010.11.16———android Camera 拍照的
  9. Android(安卓)4.0 开发环境离线安装(Linu
  10. Android(安卓)读取手机音乐,视频,图片