我正在为我的应用程序使用xamarin表单。
我正在将以下代码用于Google地图。该代码可以在线正常运行。当我杀死该应用程序并在离线状态下打开该应用程序时,地图将显示为附件图像。 谁能帮我解决这个问题。
formmap.xaml:
<local:CustomMap x:Name="customMap" Grid.Row="0" Grid.Column="0" Margin="0" MapType="Street" HasZoomEnabled="True" IsShowingUser="True" WidthRequest="{x:Static default:App.ScreenWidth}" HeightRequest="{x:Static default:App.ScreenHeight}" VerticalOptions="FillAndExpand" />
formmap.xaml.cs
customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(13.008677, 80.208194), Xamarin.Forms.Maps.Distance.FromMiles(6)));
androidmenifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="internalOnly" package="myapp" android:versionName="1.0.1" android:versionCode="6">
<uses-sdk android:minSdkVersion="20" android:targetSdkVersion="28" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" android:required="false" />
<application android:label="myapp" android:largeHeap="true" android:icon="@drawable/Icon" android:theme="@style/MyTheme">
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
<meta-data android:name="com.google.android.geo.API_KEY" android:value="mykey" />
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="myapp.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>
</manifest>
CustomMap.cs:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Xamarin.Forms;
using Xamarin.Forms.Maps;
namespace myprj.CustomControls
{
public class CustomMap : Map
{
public static readonly BindableProperty RouteCoordinatesProperty =
BindableProperty.Create<CustomMap, ObservableCollection<CustomPosition>>(p => p.RouteCoordinates, new ObservableCollection<CustomPosition>());
public static readonly BindableProperty CustomPinsProperty =
BindableProperty.Create<CustomMap, ObservableCollection<CustomPin>>(p => p.CustomPins, new ObservableCollection<CustomPin>());
public ObservableCollection<CustomPosition> RouteCoordinates
{
get { return (ObservableCollection<CustomPosition>)GetValue(RouteCoordinatesProperty); }
set { SetValue(RouteCoordinatesProperty, value); }
}
public ObservableCollection<CustomPin> CustomPins
{
get { return (ObservableCollection<CustomPin>)GetValue(CustomPinsProperty); }
set { SetValue(CustomPinsProperty, value); }
}
public CustomMap()
{
RouteCoordinates = new ObservableCollection<CustomPosition>();
}
public CustomMap(MapSpan region) : base(region)
{
}
}
}