Solution 1 :
You are missing the plugin initialization in the Android project.
using Xamarin.Forms.GoogleMaps.Android;
namespace App.Droid
{
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
// more stuff here...
var platformConfig = new PlatformConfig
{
BitmapDescriptorFactory = new CachingNativeBitmapDescriptorFactory()
};
Xamarin.FormsGoogleMaps.Init(this, savedInstanceState,
platformConfig); // initialize for Xamarin.Forms.GoogleMaps
}
LoadApplication(new App());
}
}
}
Solution 2 :
At first, you can download the android studio and check the log in the emulator to find what type of error appears and causes the app crash.
In addition, there is already a sample in the github for this nuget package, have you tried that?
Finally, at the 4th step, you not only need to add these permissions into the AndroidManifest.xml, but also need the user to grant the dangerous permissions such as the location permission by himself.
So you can do a run-time permission check and request the permission according to the official document:https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/permissions?tabs=windows
and https://learn.microsoft.com/en-us/xamarin/essentials/permissions?tabs=android
Problem :
I create a blank app in xamarin form for Android. when i run blank app in emulator thas work exactly, but when add Xamarin.Form.GoogleMaps to my page and run in emulator show error!
error message = “Application has stopped”
I did the following to add Xamarin.Form.GoogleMaps .
1- download latest version Xamarin.Form.GoogleMaps from Nuget.
2- Add
<meta-data android_name="com.google.android.maps.v2.API_KEY" android_value="my api key" />
to AndroidManifest.xml
3- add all permission i need! list of permission
<uses-permission android_name="android.permission.ACCESS_NETWORK_STATE" />
<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.ACCESS_MOCK_LOCATION" />
<uses-permission android_name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android_name="android.permission.INTERNET" />
<uses-permission android_name="android.permission.WRITE_EXTERNAL_STORAGE" />
4- add xmlns:maps="clr-namespace:Xamarin.Forms.GoogleMaps;assembly=Xamarin.Forms.GoogleMaps"
to my page
5- and add <maps:Map VerticalOptions="Fill" HorizontalOptions="Fill"/>
Friends, how can I solve this problem of closing the app?
Comments
Comment posted by Jason
have you looked at the logs?
Comment posted by jafar
@Jason no, how can i see the logs?
Comment posted by Jason
look at the “Application Ouput” window in VS, or use the Android tools to view the device logs
Comment posted by jafar
@Jason I saw the logs, but since I’m a newbie, I can’t figure out where the problem is?
Comment posted by jafar
don’t find namespace
Comment posted by link
I found the code of this command in address