I am trying to integrate google maps to Xamarin Android. However, received the error, as written in the title. This error appeared on my SetContentView (Resource.Layout.Main); as shown below where:
Error occurred in MainActivity.cs
My google play services for maps is up-to-date. I have tried cleaning and rebuilding the project, also restarting VS did not work for me. Non of the forums answered my questions.
These are what is written in my project for:
MainActivity.cs
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Gms.Maps;
namespace Google_maps.Droid
{
[Activity (Label = "@string/Google_maps.Android", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity, IOnMapReadyCallback
{
private GoogleMap mMap;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
SetUpMap();
}
private void SetUpMap()
{
if (mMap == null)
{
FragmentManager.FindFragmentById<MapFragment>(Resource.Id.map).GetMapAsync(this);
}
}
public void OnMapReady(GoogleMap googleMap)
{
mMap = googleMap;
}
}
}
Main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
Strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Click Me!</string>
<string name="app_name">Google_maps.Android</string>
<string name="google_maps_key">my_API_key</string>
<string name="Google_maps.Android">Google maps</string>
</resources>
and finally,
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="Google_maps.google_mapsAndroid" android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="15" />
<application android:label="Google_maps.Android" android:icon="@drawable/Icon">
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.maps.V2.API_KEY" android:value="@string/google_maps_key" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
</manifest>
For additional information, I followed a method from a youtuber, Joe Rock, where he teaches us on how to setup google maps. Here is the link to his video:
https://www.youtube.com/watch?v=W6Q0olRPsus
If you look down the comment section, you can see many others are having the same problem too. This video was made 2 years ago, so I would understand why it would not work at this current situation. However, I would appreciate it if you guys can enlighten me for the proper way to integrate google maps to my android mobile application, if somehow, this method is no longer reliable. Thank you in advance.
regards, Xamarin and programming newbie.
Edit:
When I drag my mouse to SetContentView (Resource.layout.Main)
it says void Activity.SetContentView(int LayoutResID) (+2 overloads)
set the activity content on a layout resource.
Should I be concern about this?