-4
using Android.App;
using Android.Widget;
using Android.OS;
using System;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Gms.Maps;
using Android.Gms.Maps.Model;
using System.Configuration;


namespace googlemaps
{
    [Activity(Label = "googlemaps", MainLauncher = true, Icon = "@drawable/icon")]


    MainActivity


    public class MainActivity: Activity, IOnMapReadyCallback
    { 
        private GoogleMap GMap;


        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            // Set our view from the "main" layout resource  
            SetContentView(Resource.Layout.XMLFile1);

            SetUpMap();
        }
        private void SetUpMap()
        {
           if (GMap == null)
            {

                MapFragment mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map).GetMapAsync(this);
            }
        }
        public void OnMapReady(GoogleMap googleMap)
        {
            MarkerOptions MarkerOptions = new MarkerOptions();
            MarkerOptions.SetPosition(new LatLng(16.03, 108));
            MarkerOptions.SetTitle("My Postion");
            googleMap.AddMarker(MarkerOptions);
            googleMap.UiSettings.ZoomControlsEnabled = true;
            googleMap.UiSettings.CompassEnabled = true;
            googleMap.MoveCamera(CameraUpdateFactory.ZoomIn());

        }


        }

    }

and

'Fragment' does not contain a definition for 'GetMapAsync' and no extension method 'GetMapAsync' accepting a first argument of type 'Fragment' could be found (are you missing a using directive or an assembly reference?) googlemaps

Thank you in advance

  • Please **do not** post a screenshot of your code - post your code **as text** and **format it properly** using the `{ .... }` keys in the editor – marc_s Mar 28 '17 at 11:06
  • thank you for the advice but it's my first time to ask and i don't know how to ask Could u help me ? – Essam Mohsen Mar 28 '17 at 11:11
  • As I said - do **not** post a screenshot of your code - **post your code** directly as text, and format the text properly by highlighting it and clicking on the `{ .... }` button in the editor toolbar - the code will be indented from the left by 4 spaces and thus will show up as code, nicely syntax highlighted and all ..... that makes looking at it much simpler, and thus increases your chances of someone studying it and providing an answer$ – marc_s Mar 28 '17 at 11:15
  • Whatever the `Fragment` type is, it does not have a method called `GetMapAsync`. And Since `FindFragmentById` (apparently) returns a `Fragment` instance, you can't do that. Its like trying to do `String.DoSomethingThatAStringCantDo()` - there is no such method on string. – Crowcoder Mar 28 '17 at 12:41

1 Answers1

0

Your method "OnMapReady" needs to override the base class's method.

public override void OnMapReady(GoogleMap gmap)
{
    //dostuff
}

I'm not 100% because I've never done this specifically, but I'm fairly certain it's complaining about this callback method.

I used this to find this out. This is the native Java for android development, but it mostly translates pretty well over into Xamarin from experience.

Community
  • 1
  • 1
Tom Johnson
  • 679
  • 5
  • 15