1

I'm using this code from xamarin studio sample for showing google maps android version 2 in my project:

_mapFragment = SupportFragmentManager.FindFragmentByTag("map") as SupportMapFragment;
            if (_mapFragment == null)
            {
                GoogleMapOptions mapOptions = new GoogleMapOptions()
                    .InvokeMapType(GoogleMap.MapTypeSatellite)
                        .InvokeZoomControlsEnabled(false)
                        .InvokeCompassEnabled(true);

                FragmentTransaction fragTx = SupportFragmentManager.BeginTransaction();
                _mapFragment = SupportMapFragment.NewInstance(mapOptions);
                fragTx.Add(Resource.Id.googleMap  , _mapFragment, "map");
                fragTx.Commit();
            }

and this is my layout

 <FrameLayout
    android:id="@+id/googleMap"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

but it always return null.

I run the sample of xamrin also. while it works fine ago. but now it is not working. No errors or exceptions. just _mapFragment is null.

from where could be this?

EDIT

I change the layout code to :

  <fragment 
    android:id="@+id/googleMap"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
      class="com.google.android.gms.maps.SupportMapFragment" />

and the first line of code to this:

_mapFragment = SupportFragmentManager.FindFragmentById (Resource .Id.googleMap ) as SupportMapFragment;

now, the FragmentManager not returns null. but yet the map don't loaded but yet the fragment is a white page and not zooming out and zooming in works.

I use this code for getting map, but map fragment returns null:

private void SetupMapIfNeeded()
    {
        if (mapView == null)
        {
            mapView = _mapFragment.Map;
            if (mapView != null)
            {
                mapView .MapType =1;
                mapView .MyLocationEnabled = true ;

            }
        }
    }
Husein Behboudi Rad
  • 5,434
  • 11
  • 57
  • 115

2 Answers2

0

For you second problem:

now, the FragmentManager not returns null. but yet the map don't loaded but yet the fragment is a white page and not zooming out and zooming in works.

This problem is usually derived from a problem in referencing google-play-service library. Take a look at this blog post I wrote on how to integrate Google Maps in your application, especially the first 3 steps:

Google Maps API V2

another cause of this could be that you haven't configured the Google API Console properly, so I suggest you to take a look at this guide as well:

Google Maps API V2 Key

another reason that may cause this is if you have some kind of problem in your permissions in the manifest file. You can look at the first guide for the needed permissions as well.

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • Thanks for reply, I think you should be right. Actually xamarin have specific way for reffering to google play libraries. he descripe it https://github.com/xamarin/monodroid-samples/tree/master/MapsAndLocationDemo_v2 . porobably I have some problems by this. but I do not know. I re add the googleplayservices to propeject but ye the problem is live – Husein Behboudi Rad May 23 '13 at 08:07
  • Notice that, MAYBE THE GOOGLE MAP IS NOT AVAILABLE IN YOUR REGOIN(FOR EXAMPLE MIDDLE EAST COUNTRIES) – Husein Behboudi Rad Oct 14 '13 at 11:22
0

Maybe the key isn't correct. You can try the following thing:

  • Be sure you use your right packet name like this
  • allow using internet on manifest

Community
  • 1
  • 1
Tai Dao
  • 3,407
  • 7
  • 31
  • 54