(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 ...
随机推荐
- golang Aes
package models import ( "bytes" "crypto/aes" "crypto/cipher" "err ...
- action接收到来自jsp页面的请求时出现中文乱码问题处理方法
写JSP程序时,在Servlet中取请求参数时出现了乱码,当然,这种乱码问题再简单不过了.由于在JSP中使用了GBK作用页面的编码,那么提交的中文信息自然也会被按着GBK进行编码,为%xx格式的GBK ...
- 利用R语言打造量化分析平台
利用R语言打造量化分析平台 具体利用quantmod包实现对股票的量化分析 1.#1.API读取在线行情2.#加载quantmod包3.if(!require(quantmod)){4. instal ...
- HTML特殊符号编码大全
HTML特殊字符编码:往网页中输入特殊字符,需在html代码中加入以&开头的字母组合或以&#开头的数字.下面就是以字母或数字表示的特殊符号大全. ´ ´ © © > > µ ...
- 【转】基于RSA算法实现软件注册码原理初讨
1 前言 目前,商用软件和共享软件绝大部份都是采用注册码授权的方式来保证软件本身不被盗用,以保证自身的利益.尽管很多常用的许多软件系统的某些版本已经被别人破解,但对于软件特殊行业而言,注册码授权的方式 ...
- Qt开发初步,循序渐进,preRequest for 蓝图逆袭
1,使用Qt面向对象类继承创建第一个窗口主部件,使用setMinimumSize(),setMaximumSize()配置主部件窗口是否能够resize;
- 全国计算机等级考试二级教程-C语言程序设计_第14章_结构体、共用体和用户定义类型
函数的返回值是结构体类型 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> struct ...
- Mac 任何选项没有了怎么办?
1.如果需要恢复允许"任何来源"的选项,即关闭 Gatekeeper,请打开终端 2.然后使用 spctl 命令: sudo spctl --master-disable
- JavaScript中的计时器原理
理解John Resig 在 How JavaScript Timers Work. 原理分析 timer(setInterval,setTimeout)有一个很重要的概念,时间延迟的长短是不稳定的. ...
- PLSQL笔记
/*procedurallanguage/sql*/--1.过程.函数.触发器是pl/sql编写的--2.过程.函数.触发器是在oracle中的--3.pl/sql是非常强大的数据库过程语言--4.过 ...