最近项目中需要接入Google地图,遇到很多问题,现在记录下来,供以后参考。

1. 登录Google API Console,注册Android API密钥(需要翻墙 ~_~)

得到API KEY:

2. 下载Google Play 服务 SDK

即google-play-services_lib(里面包含google-play-services.jar),用SDK Manager没找到,在GitHub上下了一个:

3. 地图接入,添加marker

配置AndroidManifest.xml清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.mark.maptrackdemo"android:versionCode="1"android:versionName="1.0" ><uses-sdk android:minSdkVersion="17" android:targetSdkVersion="23" /><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><application
        android:allowBackup="false"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@android:style/Theme.NoTitleBar" ><uses-library android:name="com.google.android.maps" android:required="true" /><activity android:name=".MainActivity" ><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><meta-data
            android:name="com.google.android.maps.v2.API_KEY"android:value="AIzaSyBmemD8LhxHNbI6jG2Fttmormx-PtCGQrA" /><meta-data
            android:name="com.google.android.gms.version"android:value="@integer/google_play_services_version" /></application>
</manifest>

定义XML 布局文件,位于res/layout/activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity" ><fragment
        android:id="@+id/map"android:layout_width="match_parent"android:layout_height="match_parent"class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>

定义地图 Activity 的 Java 文件名为 MainActivity.java:

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;public class MainActivity extends FragmentActivity {// Googleplex经纬度private final LatLng googleLatLng = new LatLng(37.422277, -122.084058);@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);mapFragment.getMapAsync(onMapReadyCallback);}protected OnMapReadyCallback onMapReadyCallback = new OnMapReadyCallback() {@Overridepublic void onMapReady(GoogleMap googleMap) {//添加标记googleMap.addMarker(new MarkerOptions().position(googleLatLng).title("Marker in Googleplex"));//移动摄像头googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(googleLatLng, 13));}};
}

在具有Google服务的手机上运行,国内安卓系统会报错:Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY。
运行成功可以看到如下效果(需要翻墙,不然一片空白):

Android Google地图接入(一)相关推荐

  1. Android Google地图接入(二)

    前面完成了地图的显示,现在想要获取位置数据,需要使用到另一个API:Google Play services Location API. 接收位置更新基本流程: 1. 连接LocationServic ...

  2. uber_像Uber这样的Android Google地图样式

    uber Have you ever noticed how Uber and other few popular location-based applications have a differe ...

  3. Android Google登录接入

    一.接入准备 手机必须有Google套件 Google服务框架,Google Play商店,Google Play服务(使用su谷歌安装器下载安装) 手机必须可以翻墙 google开发者账号 二.官网 ...

  4. Android的Google地图开发

    编写这个程序之前需要有一个Google 地图 扩展库在SDK中,一般来说,android 1.5中就已经有了.如果没有的话可以在这里下载: http://code.google.com/android ...

  5. Android Google Map开发指南(三)百度地图、谷歌地图自如切换

    如果你是刚开始接触谷歌地图的话,推荐你先看一下文章: Android Google Map 开发指南(一)解决官方demo显示空白只展示google logo问题 Android Google Map ...

  6. 《ArcGIS Runtime SDK for Android开发笔记》——(13)、图层扩展方式加载Google地图...

    1.前言 http://mt2.google.cn/vt/lyrs=m@225000000&hl=zh-CN&gl=cn&x=420&y=193&z=9& ...

  7. 通过Android上的意图启动Google地图路线

    本文翻译自:Launching Google Maps Directions via an intent on Android My app needs to show Google Maps dir ...

  8. android google定位和地图

    首先在google地图这需要个 <com.google.android.maps.MapView android:id="@+id/mv"     android:click ...

  9. Android Google Map实例 - 在地图和卫星图之间切换(Android mapview)

    之前讲述的例子中显示的 为地图模式,如何你想使用类似google earth的卫星图模式显示,如何操作? 在android上将变得非常简单: 增加两个Button按钮和两个对应的Button.OnCl ...

最新文章

  1. golang 获取公网ip 内网ip 检测ip类型 校验ip区间 ip地址string和int转换 判断ip地区国家运营商
  2. 商汤科技 中科院自动化所:视觉跟踪之端到端的光流相关滤波 | CVPR 2018
  3. IOS开发高级之点餐系统的实现-01
  4. lcfirst_PHP lcfirst()函数与示例
  5. 清华大学开源迁移学习算法库:基于PyTorch实现已有算法
  6. Struts2中动态的指定返回的结果集
  7. 【转】asp.net项目在IE11下出现“__doPostBack”未定义的解决办法
  8. SQL那些事儿(十一)--ODBC,OLE-DB,ADO.NET区别
  9. H5中新增加的一些标签
  10. 配置“终端服务器授权”激活许可证服务器(转)
  11. 2015移动互联网行业趋势盘点(PPT)
  12. uniapp ios原生插件开发之component
  13. 1.Hadoop简介——为什么要使用Hadoop?什么是Hadoop?Hadoop有什么作用?
  14. The Fool HDU - 6555
  15. 牛客 郊区春游 状压+最短路
  16. 有限元方法基础-以二维拉普拉斯方程为例(附程序)
  17. 怎么办理质量管理体系认证证书ISO9001?
  18. 安卓系统应用程序开发!华为Android面试真题解析,内含福利
  19. 从逃离到成为游戏开发,40岁了我才学会编程
  20. 手把手教你搭建一个属于自己的Ghost博客

热门文章

  1. QIIME2得到PICRUSt2结果后如何分析
  2. MySQL 部署PXC集群
  3. 二叉树后序遍历非递归算法(详解)
  4. 539/CA_SI4136/SI4133/SI5351手册解读
  5. TIA博途SCL编程学习21_4个数字中的3个数字的排列组合
  6. SQL语句多表查询:【多表连查】和【子查询】
  7. 各种OOM代码样例及解决方法
  8. 【MySQL】InnoDB存储引擎
  9. vba 之判断工作表是否处于保护状态:Worksheets.ProtectContents
  10. 反编译获取apk安装包源代码步骤