gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15945
  • QQ554730525
  • 铜币25337枚
  • 威望15352点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
阅读:2199回复:1

编写最简单的android谷歌地图应用

楼主#
更多 发布于:2012-09-12 09:55
<p>有多简单呢?看,只是显示了一下地图而已:</p><p><a href="http://marshal.easymorse.com/wp-content/uploads/2010/04/image19.png"><img style="border-width: 0px; display: inline;" title="image" border="0" alt="image" src="http://marshal.easymorse.com/wp-content/uploads/2010/04/image_thumb18.png" width="200" height="329"/></a> </p><p> <span id="more-2512"></span><p>想编写android谷歌地图应用,准备工作比编写其他应用要麻烦一些。因为:</p><ol><li>android谷歌地图API,不是开源免费的,是谷歌的私有软件,虽然是免费的; </li><li>这个API,需要时刻依赖向谷歌下载地图信息。 </li></ol><p>那么第一条还比较好办。我这里用的是android 2.1,用其他版本比如1.5的,需要做的类似。需要在项目中导入google map api,默认情况下是没有的。默认情况是android某个版本比如android 2.1,现在需要改为对应版本的google apis,版本要和android版本一致。这个google apis是同版本的android超集,包含了google的私有应用api。比如:</p><p><a href="http://marshal.easymorse.com/wp-content/uploads/2010/04/image20.png"><img style="border-width: 0px; display: inline;" title="image" border="0" alt="image" src="http://marshal.easymorse.com/wp-content/uploads/2010/04/image_thumb19.png" width="526" height="248"/></a></p><p>这样就可以在项目中使用比如:</p><blockquote><p>com.google.android.maps.MapActivity</p></blockquote><p>这还不够,google需要一个签名指纹的机制,要先到google注册,并把这个指纹包含在应用中,才可以下载到地图信息。也就是说每次下载地图信息要带着这个指纹信息。</p><p>指纹信息的注册和获取都是免费的。</p><p>指纹有两种:</p><ol><li>用于开发的debug指纹,只能使用在自己的debug应用程序里; </li><li>正式的指纹。 </li></ol><p>这里只需要第一种就可以了。</p><p>操作步骤是,首先开发环境要有JDK,应该都有的吧。进入JDK的bin目录,执行:</p><p><a href="http://marshal.easymorse.com/wp-content/uploads/2010/04/image21.png"><img style="border-width: 0px; display: inline;" title="image" border="0" alt="image" src="http://marshal.easymorse.com/wp-content/uploads/2010/04/image_thumb20.png" width="559" height="69"/></a> </p><p>会得到类似:</p><p><a href="http://marshal.easymorse.com/wp-content/uploads/2010/04/image22.png"><img style="border-width: 0px; display: inline;" title="image" border="0" alt="image" src="http://marshal.easymorse.com/wp-content/uploads/2010/04/image_thumb21.png" width="569" height="59"/></a> </p><p>把指纹部分,复制下来。</p><p>然后访问:</p><blockquote><p><a href="http://code.google.com/intl/zh-CN/android/add-ons/google-apis/maps-api-signup.html">http://code.google.com/intl/zh-CN/android/add-ons/google-apis/maps-api-signup.html</a></p></blockquote><p>这里还有个前提,就是你要有google帐号,并且登录。</p><p>把刚才的md5指纹,复制到红框位置:</p><p><a href="http://marshal.easymorse.com/wp-content/uploads/2010/04/image23.png"><img style="border-width: 0px; display: inline;" title="image" border="0" alt="image" src="http://marshal.easymorse.com/wp-content/uploads/2010/04/image_thumb22.png" width="449" height="117"/></a> </p><p>并且勾选同意协议。</p><p>提交后,会看到:</p><p><a href="http://marshal.easymorse.com/wp-content/uploads/2010/04/image24.png"><img style="border-width: 0px; display: inline;" title="image" border="0" alt="image" src="http://marshal.easymorse.com/wp-content/uploads/2010/04/image_thumb23.png" width="543" height="358"/></a> </p><p>其实主要是得到红框的密钥。然后在程序或者布局文件中,凡是用到MapView的地方,加入或者设置androidLapiKey属性,就可以了。</p><p>代码其实很简单:</p><blockquote><p>public class LocationActivity extends MapActivity {      <br/>    private MapView mapView;       <br/>    private MapController mapController; </p><p>    @Override      <br/>    public void onCreate(Bundle savedInstanceState) {       <br/>        super.onCreate(savedInstanceState);       <br/>        setContentView(R.layout.main);       <br/>        mapView = (MapView) findViewById(R.id.map_view);       <br/>        Log.i("welcome", "created map activity.");       <br/>    } </p><p>    @Override      <br/>    protected boolean isRouteDisplayed() {       <br/>        return false;       <br/>    } </p><p>}</p><p> </p></blockquote><p>使用的布局文件:</p><blockquote><p><LinearLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android%22">http://schemas.android.com/apk/res/android"</a><br/>    android:orientation="vertical" android:layout_width="fill_parent"       <br/>    android:layout_height="fill_parent">       <br/>    <com.google.android.maps.MapView       <br/>        android:id="@+id/map_view" android:layout_width="fill_parent"       <br/>        android:layout_height="fill_parent" android:enabled="true"       <br/>        android:clickable="true" android:apiKey="xxxxxxxxxxxxxx" />       <br/></LinearLayout></p></blockquote>
喜欢0 评分0
hongyu315
路人甲
路人甲
  • 注册日期2012-12-11
  • 发帖数2
  • QQ
  • 铜币105枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2012-12-11 13:38
不错 这里面还有android相关知识呢<div><br/></div>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部