原文 Xamarin.android google map v2android
总结上述的步骤,在Android里面要使用Map这样的功能时,并不像IOS同样,只要拖拉一个MapView到你的Layout View就能够.所须要的步骤比较繁琐.这些步骤又能够被咱们分为两大部份.要使用Google Map在你的装置上web
接下来咱们就开始如何在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.keystoreapi
1.2 开启终端机窗口,你能够直接输入底下指令来取得你的SHA1指纹凭证. 在[USERNAME]的部分必需要改为你的使用者名称。
keytool -list -v -keystore /Users/[USERNAME]/.local/share/
Xamarin/Mono\ for\ Android/
debug.keystore -alias androiddebugkey -storepass android -keypass androidapp
指令执行成功后能够看到以下图的信息,其中SHA1算法后面有一串16进位的数值。这就你我的的指纹凭证,这部分是咱们稍后在Google APIs网站上创建API Key会须要用到。eclipse
2.1前往Google APIS网站去创建你的Google API( https://code.google.com/apis/console/ )ide
按下画面中的Create Project 按钮来创建一个Google API Project网站
3.3 在创建钥匙的时候会须要刚刚在debug.keystore 里面的SHA1算法指纹凭证.ui
3.4 从计算机中复制你的SHA1算法,贴到Configure Android Key for Xamarin Google Map API Android v2 窗口里面。在你的SHA1指纹凭证后打上一个分号「;」接着输入你应用程序的package name. 新增完成后按下肯定。
注:你的应用程序package name 是来自你在创建Android时,在AndroidManifest.xml档案里面所输入的 package name.这部分两边的设定如果不同,或致使你的地图没法显示.this
4.3 Binding Google Play Services
安装好Google Play Services后,接下来要在Xamarin.Android项目里面Binding Java binding library. 这边有两个方式来绑定:
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…
<?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" />