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.

4

7 回答 7

8

将 maps_attr.xml 文件从库项目复制到项目的 values 文件夹中。

于 2013-05-14T22:39:45.333 回答
1

您还应该导入 google-play-services_lib 项目 (/extras/google/google_play_services/libproject/google-play-services_lib) - 在识别出 cameraTargetLat 和其他项目并生成 R.java 之后。

于 2013-03-27T11:20:30.763 回答
0

我解决了它只是将以下元数据添加到 AndroidManifest.xml

 <meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
于 2014-01-07T10:27:12.920 回答
0

1,将两个外部 jar 包含到项目
2,将 \extras\google\google_play_services\libproject\google-play-services_lib\res\values\maps_attrs.xml 复制到项目值文件夹
3,将 google-play-services_lib 复制到工作区看起来没有必要在我的测试中。

更新: java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable 在 android

于 2013-09-02T10:42:32.063 回答
0

/extras/google/google_play_services/libproject/google-play-services_lib您应该在项目中作为库导入。

  1. 在 处导入一个已有的android项目/extras/google/google_play_services/libproject/google-play-services_lib,但记得COPYING IT TO WORKSPACE(重要,可能它原来所在的路径出现错误)
  2. 查看项目的属性->Android 设置并添加库“ google-play-services
  3. 请记住将android-support-v4.jar&添加google-play-services.jar到您的外部 JAR
于 2013-06-19T09:35:10.047 回答
0

可能这个答案可以帮助某人。
这是由于一个愚蠢的错误,两个项目,即。Sample project of Map并且Google play service项目必须位于同一目录中,否则将无法正确引用在此处输入图像描述

您需要将两个项目的项目复制到工作场所,或者如果您不想复制,所以不要为这两个项目都这样做,这是故障。如果你做得正确,那么你会发现这个

在此处输入图像描述

于 2015-12-22T05:47:02.713 回答
-1

您必须xmlns:map="http://schemas.android.com/apk/res-auto"在布局 xml 中包含使用map元素。

R 文件由 Eclipse自动生成,您可以在gen目录中找到它。永远不要编辑这个文件!在某些情况下,您会发现不止一个 R 文件,例如当您向项目添加库时,例如google-play-services_lib. 你总是可以在这样的代码中引用这个文件......

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

如果你想配置你的地图,可以通过XML AttributesProgrammatically来实现。

于 2013-01-25T11:30:48.463 回答