6

I just started using MapFragments, and I can get the Map to show in my Activity. I just use a simple XML-layout, and it works as expected:

enter image description here

Now, I need to get the Fragment in code, so I can start interacting with the Map. This is where I run into problems:

enter image description here

As you can see, the MapFragment (or getFragmentManager) cannot be resolved to a type. I am targeting Android 4, API level 17:

enter image description here

and you can also see that I am referencing the Googke Play library.

Here is the Manifest, just for clarity:

enter image description here

So, the big question is: why can't I resolve MapFragment? What am I missing?

As a side note: SupportMapFragment seems to resolve OK, but that's not what I want.

halfer
  • 19,824
  • 17
  • 99
  • 186
Ted
  • 19,727
  • 35
  • 96
  • 154
  • 1
    Your build target should be something like Google APIS 4.2, not just Android 4.2. I'd write a more in depth answer but have to step away in 2 minutes sorry. You can ge the Google APIs 4.2 from the SDK manager. If it's unanswered later, I can provide a more detailed response. – Mike dg Jan 18 '13 at 20:14
  • 1
    @Mikedg: The question is about Maps V2, and your comment is about Maps V1. – CommonsWare Jan 18 '13 at 20:18
  • 4
    When you add the `import` statement for `com.google.android.gms.maps.MapFragment`, what happens? – CommonsWare Jan 18 '13 at 20:19
  • Disregard my top comment, Mark was correct. – Mike dg Jan 18 '13 at 20:32
  • 1
    @CommonsWare Thats weird. If I manually add "import com.google.android.gms.maps.MapFragment", then it finds the MapFragment in the code. Usually, Eclipse suggest to import it by itself, so I never thought of doing it manually. – Ted Jan 18 '13 at 23:16
  • So, CommonsWare, if you want another correct answer in the bag, answer it and Ill mark it =) Btw, you answer a lot of questions here on SO, do you have time for anything else? ;-) – Ted Jan 18 '13 at 23:17

2 Answers2

23

To use MapFragment, you need the Android library project attached to your app (as you had) and the import statement for com.google.android.gms.maps.MapFragment. Based on your comments, the latter part was the issue.

Usually, Eclipse suggest to import it by itself, so I never thought of doing it manually.

I have run into that problem on occasion as well, where -- steadfastly refuses to add an import. I have not been able to come up with a reproducible scenario, and it happens infrequently enough that I just shrug, add it manually, and move along to other things. I'm also uncertain whether the problem is with Eclipse or with any ADT extensions to the import resolver.

Besides, I went without Eclipse for a long time in Android development, typing in import statements manually, and so I'm kinda used to it.

Btw, you answer a lot of questions here on SO, do you have time for anything else? ;-)

I am a fast typist, courtesy of several years as a teenager typing on a manual typewriter.

(For you young'uns reading this, a "typewriter" was basically a keyboard directly connected to a printer, and a "manual typewriter" was one that use the mechanical action of pressing the keys to actually put the letters on the paper, and therefore worked without electricity. Also, you are cordially invited to get off my lawn.)

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • haha, im not that young. Im perfectly aware of typewriters, AMIGA 500, Commodore 64, tapes, autoexec.bat, config.sys, "Lost Patrol" etc etc =) – Ted Jan 18 '13 at 23:31
0

Manually add the import, import com.google.android.gms.maps.MapFragment; I have been facing the same issue, And tried to resolved it for 3 days and the solution is that easy

SwapnilKumbhar
  • 347
  • 2
  • 5
  • 17