gooleMap

来源:互联网 发布:responsebody返回json 编辑:程序博客网 时间:2024/05/29 03:18

开发基于谷歌地图的应用和普通的android应用差不多都要使用它提供给我们的类库,所不同的是google map的类库不是android平台的基本类库,是google api的一部分,所以建立项目时,SDK要选择Google APIs;

还有一点,开发基于地图的应用时候需要使用google map的APIkey,必须先申请key,然后才能开发基于地图的应用。

下边分步骤记录下,整个过程:

 一、申请google Maps API key(用于开发和debug)

为了能顺利的申请Android Map API Key,必须要准备google的账号和系统的证明书。一般Google发布Key都需要Google账号,Google账号是通用的,Gmail的账号 就可以。当一个程序发布时必须要证明书,证明书其实就是MD5.我们这里并不是发布,而只是为了开发测试,可以使用Debug版的证明书,下面我们就来学 习如何申请Debug版的Key:

1.找到你的debug.keystore文件

在Eclipse工具下,选择windows-->Preference-->Android-->Build, 其中Default debug keystore的值便是debug.keystore的路径了。

2.取得debug.keystore的MD5值

首先cmd命令行进入debug.keystore文件所在的路径,执行命令:keytool -list -keystore debug.keystore ,这时可能会提示你输入密码,这里默认的密码是“android",这样即可取得MD5值。

注:输入keytool -list -keystore debug.keystore  有可能列出的不是MD5,这时需要  keytool -list -v -keystore debug.keystore 这样就把三种指纹证书全部列出来了,包括MD5、SHA1、SHA256。(密钥口令是android)

点击creat 会出现你的地图api的密钥 一个xml文件

OK 现在就可以进入map代码的编写了 代码如下

 keytool -list -v -keystore debug.keystore 这样就把三种指纹证书全部列出来了,包括MD5、SHA1、SHA256。(密钥口令是android)
package bsn.google.map;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;public class MapView extends MapActivity{private  com.google.android.maps.MapView mapView;     private MapController mapController; @Overrideprotected void onCreate(Bundle icicle) {super.onCreate(icicle);setContentView(R.layout.main);mapView=(com.google.android.maps.MapView) findViewById(R.id.test_mapview);this.mapView.setBuiltInZoomControls(true);//设置多点触摸放大    mapView.setSatellite(false);//设置地图为卫星地图//geopoint 对象是google API 提供的对象   http://code.google.com/intl/zh-CN/android/add-ons/google-apis/reference/index.html//    GeoPoint geoPoint=new GeoPoint(39000000, 116000000);     this.mapController=mapView.getController();     this.mapController.setZoom(11);// Sets the zoomlevel of the map。。     this.mapController.animateTo(getCurrentGeoPoint());     }@Overrideprotected boolean isRouteDisplayed() {     //这个方法被继承 但是它是干什么的?//网上说这个方法是用来表示我们是否显示一些路线信息。这个通常在地图的飞行模式才使用,所以我们返回falsereturn false;}//此方法用locationManager 来获取位置 并在mapView上显示出来private GeoPoint getCurrentGeoPoint(){LocationManager locationManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE);Location   location=locationManager.getLastKnownLocation(locationManager.NETWORK_PROVIDER);return new GeoPoint((int)(location.getLatitude()*1e6), (int)(location.getLongitude()*1e6));}}
哎上传图片

    * get userinfo failed


    Ok先到这里,待续