(6)Xamarin.android google map v2
原文 Xamarin.android google map v2
- 从你计算机里的keystore里面查询个人的指纹凭证(SHA1)。
- 用SHA1指纹凭证到Google APIs网站申请key。
- 在Xamarin里的Android SDK Manager去安装Google Play services。
- 在Xamarin.Android项目中加入Google Play Services component。
(原生的Android项目必须在这一步骤加入google-play-services_lib的Library。) - 新建一个项目并且在AndroidManifest加入相关的权限设定。
- 在layout 画面的Main.axml 中加入地图控件
总结上述的步骤,在Android里面要使用Map这样的功能时,并不像IOS一样,只要拖拉一个MapView到你的Layout View就可以.所需要的步骤比较繁琐.这些步骤又可以被我们分为两大部份.要使用Google Map在你的装置上
- 首先你要先上Google APIs网站上去开启与Google Map相关的服务.
- 接着才到Xamarin.Android项目中进行所有需要的设定修改.
接下来我们就开始如何在Xamarin.Android项目里使用Google map的相关设定:
1.1在Xamarin环境中,当我们装好Xamarin.android后,我们要在底下的路径去取得你的SHA1指纹凭证。
指纹凭证被放置在debug.keystore里面,在Windows与OSX的存放路径不一样,请参考下列路径:
Windows - C:\Users\[USERNAME]\AppData\Local\Xamarin\Mono for Android\debug.keystore OSX - /Users/[USERNAME]/.local/share/Xamarin/Mono for Android/debug.keystore
1.2 开启终端机窗口,你可以直接输入底下指令来取得你的SHA1指纹凭证. 在[USERNAME]的部分必须要改成你的使用者名称。
keytool -list -v -keystore /Users/[USERNAME]/.local/share/
Xamarin/Mono\ for\ Android/
debug.keystore -alias androiddebugkey -storepass android -keypass android
指令执行成功后可以看到如下图的信息,其中SHA1算法后面有一串16进位的数值。这就你个人的指纹凭证,这部分是我们稍后在Google APIs网站上建立API Key会需要用到。

2.1前往Google APIS网站去建立你的Google API( https://code.google.com/apis/console/ )
按下画面中的Create Project 按钮来建立一个Google API Project



3.1 按下左边API Access的标签.


3.3 在建立钥匙的时候会需要刚刚在debug.keystore 里面的SHA1算法指纹凭证.
3.4 从计算机中复制你的SHA1算法,贴到Configure Android Key for Xamarin Google Map API Android v2 窗口里面。在你的SHA1指纹凭证后打上一个分号「;」接着输入你应用程序的package name. 新增完成后按下确定。
注:你的应用程序package name 是来自你在建立Android时,在AndroidManifest.xml档案里面所输入的 package name.这部分两边的设定若是不一样,或导致你的地图无法显示.




4.3 Binding Google Play Services
安装好Google Play Services后,接下来要在Xamarin.Android项目里面Binding Java binding library. 这边有两个方式来绑定:
- 使用 Google Play Services component
- 手动bind the Google Play Services client library,这个方法比较类似在eclipse中开发使用Google Map的方式
Google Play Services component是Xamarin帮我们简化的Binding Java binding library所需要做的步骤,只要引用这个组件,就可以很轻松的Binding Java binding library.所以在这部分我们选择使用Google Play Services component.
4.4 新增Google Play Services 组件
展开你的Android Map项目,在Components文件夹按下鼠标右键,在弹出的窗口上点选 Get More Components…


开启专案中的AndroidManifest.xml档案,新增下方的Xaml档案权限。
在 package="com.xamarin.docs.android.mapsandlocationdemo2"与 <permission android:name="<PACKAGE NAME>.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
这两个地方要将package name修改成你的Package name.
标签里面Key值.这个Key是刚刚在Google APIs里面建立的API Key。完整的修改请参照下方Xml档案:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="4.5"package="com.xamarin.docs.android.mapsandlocationdemo2" android:versionCode="6">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />
<!-- Google Maps for Android v2 requires OpenGL ES v2 -->
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<!-- We need to be able to download map tiles and access Google Play Services-->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Allow the application to access Google web-based services. -->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Google Maps for Android v2 will cache map tiles on external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Google Maps for Android v2 needs this permission so that it may check the connection
state as it must download data -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Permission to receive remote notifications from Google Play Services -->
<!-- Notice here that we have the package name of our application as a prefix on the permissions. -->
<uses-permission android:name="<PACKAGE NAME>.permission.MAPS_RECEIVE" />
<permission android:name="<PACKAGE NAME>.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
<!-- These are optional, but recommended. They will allow Maps to use the My Location provider. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission >android:name="android.permission.ACCESS_FINE_LOCATION" />
<application android:label="@string/app_name">
<!-- Put your Google Maps V2 API Key here. -->
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="YOUR_API_KEY" />
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />

注:要看到地图被加载,你的Android仿真器必须是要有支持Google Play service的版本。若是仿真器本身如果没有 支持Google Play service,那你的地图会无法显示.

- Obtaining a Google Maps API Key
http://docs.xamarin.com/guides/android/platform_features/maps_and_location/obtaining_a_google_maps_api_key - Maps API
http://docs.xamarin.com/guides/android/platform_features/maps_and_location/part_2_-_maps_api - Google Maps Android API v2
https://developers.google.com/maps/documentation/android/
(6)Xamarin.android google map v2的更多相关文章
- Android Google Map v2具体解释:开发环境配置
Android Google Map v2具体解释:开发环境配置 --转载请注明出处:coder-pig 说在前面: 说到地 ...
- (14)[Xamarin.Android] 异步的网络图片下载
原文 [Xamarin.Android] 异步的网络图片下载 在设计要从网络上接大量数据并且显示在Android Listview中,而这些资料是利用Json格式传送并且数据中包含这图片档案. 那在X ...
- [Xamarin.Android] 如何使用Google Map V2 (转帖)
Google Map v1已經在2013年的3月開始停止支援了,目前若要在你的Android手機上使用到Google Map,就必須要使用 到Google Map v2的版本.在Xamarin要使用G ...
- NDK笔记(二)-在Android Studio中使用ndk-build
前面一篇我们接触了CMake,这一篇写写关于ndk-build的使用过程.刚刚用到,想到哪儿写哪儿. 环境背景 Android开发IDE版本:AndroidStudio 2.2以上版本(目前已经升级到 ...
- Appium移动自动化测试(二)--安装Android开发环境
继续Appium环境的搭建. 第二节 安装Android开发环境 如果你的环境是MAC那么可以直接跳过这一节.就像我们在用Selenium进行web自动化测试的时候一样,我们需要一个浏览器来执行测试 ...
- Appium移动自动化测试(二)--安装Android开发环境(转)
Appium移动自动化测试(二)--安装Android开发环境 2015-06-04 17:30 by 虫师, 35299 阅读, 23 评论, 收藏, 编辑 继续Appium环境的搭建. 第二节 ...
- Android bluetooth介绍(两): android 蓝牙源架构和uart 至rfcomm过程
关键词:蓝牙blueZ UART HCI_UART H4 HCI L2CAP RFCOMM 版本号:基于android4.2先前版本 bluez内核:linux/linux3.08系统:an ...
- NDK笔记(二)-在Android Studio中使用ndk-build(转)
前面一篇我们接触了CMake,这一篇写写关于ndk-build的使用过程.刚刚用到,想到哪儿写哪儿. 环境背景 Android开发IDE版本:AndroidStudio 2.2以上版本(目前已经升级到 ...
- Android google map 两点之间的距离
在Android google map中,有时候会碰到计算两地的距离,下面的辅助类就可以帮助你计算距离: public class DistanceHelper { /** Names for the ...
随机推荐
- word2vec配置到使用
(1)首先下载word2vec,地址:https://code.google.com/p/word2vec/,可能下载的时候有问题,google上不去,那么可以从csdn上面下载. 解压后目录如下: ...
- JQuery给元素绑定click事件多次执行的解决方法
原绑定方法: $(".subNavdiv").click(function () { ###### }); 这种方法只会在原click方法中继续添加新方法: 解决办法更改绑定方法为 ...
- smarty之缓存笔记
smarty缓存技术 在smarty中,缓存分为:普通缓存,单模版都缓存,局部缓存. 缓存:1:首选打开缓存配置项:$smarty->caching=true; 2:缓存生命周期的配置选项:$s ...
- php 表单校验函数库(判断email格式是否正确、http地址是否合法有效、手机号码是否合法)
/** * 表单校验函数库 */ /** * 判断email格式是否正确 * @param $email */ function is_email($email) { return strlen($e ...
- ASP.net MVC3里的HandleErrorAttribute
在MVC3里使用HandleErrorAttribte类,有2种方式可以使用它,一是在类或者方法上直接使用HandleError属性来定义: // 在这里声明[HandleError]public c ...
- Android仿微信界面--使用Fragment实现(慕课网笔记)
1 效果图 这里我们没有实现滑动切换view的功能 2 具体实现: 2.1 布局文件:top.xml, bottom.xml,tab01.xml,tab02.xml,tab03.xml,tab04. ...
- DNS解析服务使用的系统对网站的安全起着很重要的作用
1 采用独享的DNS服务器解析系统 DNS解析服务使用的系统对网站的安全极其重要.现在国内的DNS服务器普遍是公用的,即是你的企业网站DNS解析服务和其他许多网站都是由同一个DNS服务器提供.一旦某个 ...
- Java_SSH项目主要步骤记录
建立Spring-Struts-Hibernate的步骤整理 1. 建立web project 2. 建立hernate, action, service包 3. 右击项目,add myeclipse ...
- SVG关注复杂图形的网页绘制技术
SVG 是使用 XML 来描述二维图形和绘图程序的语言. 学习之前应具备的基础知识: 继续学习之前,你应该对以下内容有基本的了解: HTML XML 基础 如果希望首先学习这些内容,请在本站的首页选择 ...
- Aix6.1安装openssh
一.软件下载 1.官方网站下载: openssl IBM官方网站下载:https://www14.software.ibm.com/webapp/iwm/web/reg/download.do?sou ...