Android版谷歌地图V2不能得到解决,或者不是一个领域,与QUOT;名"势必空间 [英] Android google maps v2 cannot be resolved or is not a field, "name" bound to namespace

查看:280
本文介绍了Android版谷歌地图V2不能得到解决,或者不是一个领域,与QUOT;名"势必空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个机器人,显示通过GPS与谷歌地图用户位置。当我运行我的程序,我有以下错误。

i am creating a android which shows the user location with Google Maps through gps. when i run my program i have the following errors.

activity_main不能得到解决或不是字段,displayMap不能得到解决或不是字段
主要解决不了的,或者不是一个字段。起初这个错误并没有出现,但之后我保存或清洗我的项目,它似乎

activity_main cannot be resolved or is not a field, displayMap cannot be resolved or is not a field main cannot be resolved or is not a field. at first this error did not appear but after i save or clean my project, it appears

我有改变displayMap并保存,清洁我的字符串和XML文件中的项目。但错误依然存在。

i have change the displayMap and save, clean my project in strings and xml file. but the error is still there.

属性名必将名称空间 http://schemas.android.com/apk/ RES / Android的在我的Andr​​oid清单元数据是为元素已指定

Attribute "name" bound to namespace "http://schemas.android.com/apk/res/android" was already specified for element "meta-data" in my android manifest

解析器例外/MyAppName/AndroidManifest.xml:NAME属性绑定到名称空间 HTTP: //schemas.android.com/apk/res/android 元数据已经为元素指定。这个资源是我ApplicationNameApp(我的项目名称)

Parser exception for /MyAppName/AndroidManifest.xml: Attribute "name" bound to namespace "http://schemas.android.com/apk/res/android" was already specified for element "meta-data". the resource for this is my ApplicationNameApp(my project name)

这是否意味着我必须在元数据改变名?

does that means i must change the "name" under meta data?

字符串文件

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">StudentHealthApp</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="displayMap">Google Map Display</string>
</resources>

XML文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<fragment
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:id="@+id/displayMap"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</LinearLayout>

Android清单文件

Android Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.studenthealthapp"
android:versionCode="1"
android:versionName="1.0" >

<permission android:name="your.application.package.permission.MAPS_RECEIVE" android:protectionLevel="signature" />

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-features
    android:glEsVersion="0x00020000"
    android:required="true"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.studenthealthapp.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="API key value" 
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

</application>

主要的Java文件

import android.R;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends FragmentActivity {

private GoogleMap googleMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setUpMapIfNeeded();
}

private void setUpMapIfNeeded() {

    if(googleMap == null)
    {
        googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.displayMap)).getMap();

        if(googleMap != null)
        {
            setUpMap();
        }
    }

}

private void setUpMap() 
{
    //Enable MyLocation Layer of Google Map
    googleMap.setMyLocationEnabled(true);

    //Get locationManager object from System Service LOCATION_SERVICE
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    //Create a criteria object to retrieve provider
    Criteria criteria = new Criteria();

    //Get the name of the best provider
    String provider = locationManager.getBestProvider(criteria, true);

    //Get current location
    Location myLocation = locationManager.getLastKnownLocation(provider);

    //set map type
    googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

    //Get latitude of the current location
    double latitude = myLocation.getLatitude();

    //Get longitude of the current location
    double longitude = myLocation.getLongitude();

    //Create a LatLng object for the current location
    LatLng latLng = new LatLng(latitude, longitude);

    //Show the current location in Google Map
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

    //Zoom in the Google Map
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(20));
    googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("You are here!"));

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}}

我已经加入谷歌播放服务作为一个项目,谷歌播放services_lib显示为一个单独的项目文件夹,然后我在Eclipse中的应用程序。然后我添加到我的libarary由项目 - >属性 - > Android的 - >库,添加 - >谷歌播放services_lib

i have added google play services as a project, google-play-services_lib appear as a seperate project folder then my application in eclipse. then i add to my libarary by Project -> Properties -> Android -> Library, Add -> google-play-services_lib

推荐答案

更改此

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

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

删除

  import android.R;

相反,你需要

  import com.example.studenthealthapp.R;

但是,如果其在相同的包,那么就没有必要进行导入。

But if its in the same package then there is no need for import.

此外,如果你在你的资源文件有错误R.java将不会发生。因此,如果任何错误修复和清理并生成项目。

Also if you have errors in your resources files R.java will not be generated. So if any errors fix them and clean and build project.

这篇关于Android版谷歌地图V2不能得到解决,或者不是一个领域,与QUOT;名&QUOT;势必空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆