5

Today I have read the document of Google Maps Android API v2, it said the project of android-sdk\extras\google\google_play_services\samples\maps can run, but after I imported into eclipse and set the libraries of android-support-v4.jar and google-play-services.jar correctly, import com.example.mapdemo.R; in FeatureView.java (at line 24) can not find the file R.java.

almost all the java file in com.example.mapdemo need class "R", for example, the file BasicMapActivity.java need R in line 41 "setContentView(R.layout.basic_demo);" and line 71 mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();" can someone tell me how to find the class "R"?

R

.java can not create automatically because the file multimap_demo.xml have some errors in
<br><br>    &lt;fragment
<br>      android:id="@+id/map3"
<br>      android:layout_width="match_parent"
<br>      android:layout_height="match_parent"
<br>      android:layout_weight="0.5"
<br>      class="com.google.android.gms.maps.SupportMapFragment"
<br>      map:cameraTargetLat="48.85"
<br>      map:cameraTargetLng="2.35"
<br>      map:cameraZoom="8"/&gt;
<br><br>

eclipse said "cameraTargetLat", "cameraTargetLng" and "cameraZoom" can not recognized. The error information:

Multiple annotations found at this line:
    - error: No resource identifier found for attribute 'cameraTargetLat' in package 'com.example.mapdemo'
    - error: No resource identifier found for attribute 'cameraTargetLng' in package 'com.example.mapdemo'
    - error: No resource identifier found for attribute 'cameraZoom' in package 'com.example.mapdemo'

I do not know why.

If I change the code like this:
<br><br>    &lt;fragment
<br>      android:id="@+id/map3"
<br>      android:layout_width="match_parent"
<br>      android:layout_height="match_parent"
<br>      android:layout_weight="0.5"
<br>      class="com.google.android.gms.maps.SupportMapFragment"/&gt;
<br><br>

the errors disappeared, but i do not know if it can run.

Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
user2007659
  • 51
  • 1
  • 1
  • 3

7 Answers7

8

Copy the maps_attr.xml file from the library project into your project's values folder.

droidment
  • 555
  • 5
  • 7
1

You should also import google-play-services_lib project (/extras/google/google_play_services/libproject/google-play-services_lib) - after that cameraTargetLat and other ones are recognized and R.java is generated.

Oleksandr
  • 1,492
  • 3
  • 9
  • 13
0

you should import /extras/google/google_play_services/libproject/google-play-services_lib as a library in your project.

  1. Import an existing android project at /extras/google/google_play_services/libproject/google-play-services_lib, but remember COPYING IT TO WORKSPACE(important, maybe the path of its original place occurs error)
  2. See your project's properties->Android settings and add library "google-play-services"
  3. Remember to add android-support-v4.jar & google-play-services.jar to your External JARs
huzeyfe
  • 3,554
  • 6
  • 39
  • 49
BUPTOrange
  • 56
  • 1
  • 6
0

1, include both external jar to project
2, copy \extras\google\google_play_services\libproject\google-play-services_lib\res\values\maps_attrs.xml to project value folder
3, copy google-play-services_lib to workspace looks no necessary in my test.

Update: java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable in android

Community
  • 1
  • 1
0

I solved it just adding the following meta-data to the AndroidManifest.xml

 <meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
0

may be this answer can help someone.
this is due to a silly mistake, both the projects ie. Sample project of Map and Google play service project must reside on the same directory otherwise it will not referenced properlyenter image description here

you need do copy projects into workplace for both the projects or if you don't want to copy, so don't do it for both this is the glitch. if you do it properly then you will find this

enter image description here

Rishabh Agrawal
  • 1,998
  • 2
  • 25
  • 40
-1

you have to include xmlns:map="http://schemas.android.com/apk/res-auto" to your layout xml for using map element.

The R file is autogenerate by Eclipse, and you can find it in gen directory. Don't edit this file ever! In some case, you will find there more than one R file, for example when you add a library to your project, like google-play-services_lib. You always can refere to this file at code like this...

mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(com.your.package.R.id.map)).getMap();

If you want to configure your map, is posible to make it by XML Attributes or Programmatically.

jgonza73
  • 344
  • 1
  • 10