我正在开发Monodroid安卓应用。我已经添加了带有片段的谷歌地图,但地图不会显示,我也没有收到任何错误。
我的Axml代码:
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
活动代码:
protected async override void OnResume()
{
base.OnResume();
tblLocations location = Nav.GetAndRemoveParameter<tblLocations>(Intent);
LatLng latLng = new LatLng(location.Latitude, location.Longitude);
CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
builder.Target(latLng);
builder.Zoom(5);
CameraPosition cameraPosition = builder.Build();
CameraUpdate cUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);
mapFrag = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);
map = mapFrag.Map;
if (map != null)
{
map.MoveCamera(cUpdate);
}
}
我意识到这是API密钥,但我在这里缺少什么?
登录CAT输出
04-01 16:40:24.662 D/ChimeraFileApk(20730): Classloading successful. Optimized code found.
04-01 16:40:24.730 E/NEW_BHD (20811): Battery Power Supply logging Daemon start!!!!!
04-01 16:40:24.730 E/NEW_BHD (20811): Cannot run on production devices!
04-01 16:40:24.755 I/Google Maps Android API(20730): Google Play services client version: 848700004-01 16:40:24.755 I/Google Maps Android API(20730): Google Play services client version: 8487000
04-01 16:40:24.764 I/Google Maps Android API(20730): Google Play services package version: 8703436
04-01 16:40:24.804 I/art (20530): CollectorTransition marksweep + semispace GC freed 471(-32KB) AllocSpace objects, 0(0B) LOS objects, 24% free, 7MB/9MB, paused 16.348ms total 16.348ms
04-01 16:40:25.088 D/VoldConnector( 2225): SND -> {10 volume mkdirs /storage/emulated/0/Android/data/asked.askeduniversalremote/cache/}
04-01 16:40:25.220 D/Mono (20730): Assembly Ref addref Xamarin.GooglePlayServices.Maps[0xb9b18688] -> Xamarin.GooglePlayServices.Basement[0xb9b148d0]: 2
04-01 16:40:25.283 I/b (20730): Sending API token request.
04-01 16:40:25.316 I/Keyboard.Facilitator( 3831): onFinishInput()
04-01 16:40:25.357 I/LaunchCheckinHandler( 2225): Displayed asked.askeduniversalremote/md5d1d3b2ca018abe66d5a9f8b4db614c6f.ViewOtherLocationOnMapActivity,wp,ca,947
04-01 16:40:25.357 I/ActivityManager( 2225): Displayed asked.askeduniversalremote/md5d1d3b2ca018abe66d5a9f8b4db614c6f.ViewOtherLocationOnMapActivity: +947ms
04-01 16:40:25.372 E/NetlinkEvent( 299): NetlinkEvent::FindParam(): Parameter 'UID' not found
04-01 16:40:25.612 I/b (20730): Received API Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
04-01 16:40:25.612 I/c (20730): Scheduling next attempt in 431700 seconds.
04-01 16:40:25.615 I/d (20730): Saved auth token
04-01 16:40:25.719 I/SFPerfTracer( 258): triggers: (rate: 7:437) (compose: 1:20) (post: 0:21) (render: 2:51) (6:7515 frames) (7:10501)
04-01 16:40:25.719 D/SFPerfTracer( 258): layers: (3:12) (FocusedStackFrame (0xb782cb78): 0:383)* (DimLayer (0xb786b8f0): 0:2)* (StrictModeFlash (0xb7804b60): 0:50)* (StatusBar (0xb780a350): 0:2953) (com.android.systemui.ImageWallpaper (0xb781e148): 0:163)* (NavigationBar (0xb78a5528): 0:402) (DimLayer (0xb7892338): 1:14)* (asked.askeduniversalremote/md5d1d3b2ca018abe66d5a9f8b4db614c6f.WaitTimeActivity (0xb789fa28): 0:51)- (asked.askeduniversalremote/md5d1d3b2ca018abe66d5a9f8b4db614c6f.ViewOtherSitesActivity (0xb78aef90): 0:108)- (asked.askeduniversalremote/md5d1d3b2ca018abe66d5a9f8b4db614c6f.ViewOtherLocationOnMapActivity (0xb789f9e0): 7:25)
04-01 16:40:27.516 D/audio_hw_primary( 303): out_standby: enter: stream (0xb7690308) usecase(1: low-latency-playback)04-01 16:40:27.516 D/audio_hw_primary( 303): out_standby: enter: stream (0xb7690308) usecase(1: low-latency-playback)
04-01 16:40:27.616 D/hardware_info( 303): hw_info_append_hw_type : device_name = speaker04-01 16:40:27.616 D/hardware_info( 303): hw_info_append_hw_type : device_name = speaker
04-01 16:40:29.766 E/NEW_BHD (20866): Cannot run on production devices!
04-01 16:40:31.127 D/Mono (20730): [0x9e1ff930] worker finishing
04-01 16:40:31.167 D/WifiStateMachine( 2225): starting scan for
04-01 16:40:34.778 D/SLPC ( 3416): slpc_poll_loop(): handled 1
04-01 16:40:34.778 D/SLPC ( 3416): slpc_poll_handle_event(): transition
04-01 16:40:34.778 D/SLPC ( 3416): slpc_poll_loop(): about to poll...
04-01 16:40:34.778 D/sensorhub( 3416): sensorhub_poll() polling...
04-01 16:40:34.796 E/NEW_BHD (20867): Battery Power Supply logging Daemon start!!!!!
04-01 16:40:34.797 E/NEW_BHD (20867): Cannot run on production devices!
04-01 16:40:35.292 D/NetlinkSocketObserver( 2225): NeighborEvent{elapsedMs=6311820, 192.168.105.1, [C86C870B13EB], RTM_NEWNEIGH, NUD_STALE}
04-01 16:40:35.783 V/AlarmManager( 2225): sending alarm {58361af type 2 *walarm*:com.motorola.slpc.ALARM_STOWED}
04-01 16:40:35.786 D/ModalityService( 3416): StowedListener(): callback onStowedChange() -> 2
04-01 16:40:35.787 V/AlarmManager( 2225): done {58361af, *walarm*:com.motorola.slpc.ALARM_STOWED} [4ms]
04-01 16:40:35.787 D/ModalityManager( 5416): onStowedChange() -> 2, package: com.motorola.actions
更新 Logcat现在显示以下警告
04-04 09:30:07.355 W/ctxmgr ( 4204): [AclManager]checkPermissionTypeStatus: no inject permission for { uid=10019, packageName=com.google.android.gms }. Returned permission was: PACKAGE_NOT_WHITELISTED for context name=POWER_CONNECTION, account=account#-517948760#
04-04 09:30:07.358 W/ctxmgr ( 4204): [AclManager]checkPermissionTypeStatus: no inject permission for { uid=10019, packageName=com.google.android.gms }. Returned permission was: PACKAGE_NOT_WHITELISTED for context name=POWER_CONNECTION, account=account#-517948760#
答案 0 :(得分:4)
确保提供给您的Google API控制台的哈希值是正确的,您可以提供两个哈希值,一个用于debug.keystore,另一个用于生产密钥库。
检查哈希值是否正确,使用debug / production keystore运行你的应用程序检查这个代码片段的日志输出(它是用Java编写的,但我相信在Xamarin中有类似的API)并将其与一个在API控制台中:
PackageInfo info;
try {
info = getPackageManager().getPackageInfo("com.you.name", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String something = new String(Base64.encode(md.digest(), 0));
//String something = new String(Base64.encodeBytes(md.digest()));
Log.e("hash key", something);
}
} catch (NameNotFoundException e1) {
Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
Log.e("exception", e.toString());
}
答案 1 :(得分:1)
尝试添加:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
AndroidManifest.xml中的<application>
答案 2 :(得分:1)
以下是c#Implementation
private void CheckSignatureHash()
{
try
{
PackageInfo info = PackageManager.GetPackageInfo("com.package.name", PackageInfoFlags.Signatures);
string hash = "";
foreach (var sign in info.Signatures)
{
MessageDigest md = MessageDigest.GetInstance("SHA");
md.Update(sign.ToByteArray());
hash += Base64.EncodeToString(md.Digest(), Base64Flags.Default);
Console.WriteLine("***********************************");
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Console.WriteLine("KeyHash:" + hash);
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Console.WriteLine("***********************************");
}
//Toast.MakeText(this, hash, ToastLength.Short).Show();
}
catch (PackageManager.NameNotFoundException e)
{
}
catch (NoSuchAlgorithmException e)
{
}
}