Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 谷歌地图V2不适合我。有样品吗?_Android_Android Maps V2 - Fatal编程技术网

Android 谷歌地图V2不适合我。有样品吗?

Android 谷歌地图V2不适合我。有样品吗?,android,android-maps-v2,Android,Android Maps V2,我使用了许多谷歌地图V2的示例,并且我遵循了所有必要的步骤。但仍然有问题,只有地图视图显示,我的当前位置没有显示在我的模拟器上 我已经从API控制台创建了我的系统MD 5密钥和API密钥,并在清单中使用了SHA 1密钥。但还是有问题 所以请帮帮我 我的源代码: MainActivity.java package com.googlev2.android; import android.os.Bundle; import android.app.Activity; import android.

我使用了许多谷歌地图V2的示例,并且我遵循了所有必要的步骤。但仍然有问题,只有地图视图显示,我的当前位置没有显示在我的模拟器上

我已经从API控制台创建了我的系统MD 5密钥和API密钥,并在清单中使用了SHA 1密钥。但还是有问题

所以请帮帮我

我的源代码:

MainActivity.java

package com.googlev2.android;

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

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

public class MainActivity extends FragmentActivity {

private GoogleMap mMap;

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

    SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().
            findFragmentById(R.id.map);
    mMap = fm.getMap();

    mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);

    final LatLng CIU = new LatLng(35.21843892856462, 33.41662287712097);
    Marker ciu = mMap.addMarker(new MarkerOptions().position(CIU).title("My Office"));

   }

@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;
    }

  }
和activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

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


 </RelativeLayout>
<?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"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    map:cameraTargetLat="33.41662287712097"
    map:cameraTargetLng="35.21843892856462"
    map:cameraZoom="4"/>

</LinearLayout>

和AndroidManifest.xml:

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

   <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

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


    <permission 
    android:name="com.googlev2.android.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature">
    </permission>

    <uses-permission 
    android:name="com.googlev2.android.permission.MAPS_RECEIVE"/>


<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
      <!-- <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyDciL7-T3BphxGv2q-A77vNrcyJQ_sTrgI"/> -->

    <activity
        android:name="com.googlev2.android.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="AIzaSyBDUb-4cOSTeeH3XqVQHwzXL2bT0aAM2h8"/>

        -->

         <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyDiLovJFMLKEZkI5Ijtl0fKA-qApScD_Pk"/>


  </application>

</manifest>


检查是否在谷歌API控制台中添加并激活谷歌地图Android API v2。更多详细信息可在此链接中查看

如果清单文件正确,请尝试这个人

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

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


 </RelativeLayout>
<?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"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    map:cameraTargetLat="33.41662287712097"
    map:cameraTargetLng="35.21843892856462"
    map:cameraZoom="4"/>

</LinearLayout>
这是我手机上的结果

谷歌地图v2的关键是
  • 将v4支持库(用于旧设备)和
    googleplayservices.jar
    添加到您的项目中
  • 将google-play-services_lib虚拟项目作为从属项目导入。它包含非常重要的
    res/
    目录和所有本地化资源
  • 确保您创建了密钥库和密钥,并且正在使用它对APK进行签名。如果您使用的是调试密钥库,则需要将其添加到
  • 在Android设备上测试,而不是在模拟器上测试。模拟器上没有Google Play服务,您将无法获得地图。在模拟器IIRC中会出现一个白色屏幕
  • 检查您的AndroidManifest.xml是否包含所有重要条目—OpenGL 2、带密钥的元密钥、权限等

  • 在包含api密钥的元数据之后,需要添加以下行

    <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version"/>
    
    
    
    我建议您证明genymotion模拟器比默认模拟器好20倍。您可以在此处找到正确设置的说明:


    在真实设备上试用。您能告诉我们更多信息吗?向我们显示您已经拥有的代码?@Android帮助检查,您确定您正在使用map v2吗?因为现在它是google play服务的一部分,所以很难在emulator上实现。。第一部分。第二部分你一定要在谷歌API控制台中激活谷歌地图Android API v2。也要遵循本教程。你可以寄给我任何样品。其中我将更改api密钥,并显示我的当前位置。用android给我发邮件。developer20@gmail.comi同样的问题,我认为你的问题可以用上面的方法解决你说的是哪种方法?[chek this](www.vogela.com/articles/AndroidGoogleMaps/article.html)我正在尝试你的代码,不幸的是它停止了,我认为它将在模拟器上运行本教程是否有效请您使用真实设备而不是模拟器。谢谢,我认为我的错误是在模拟器上运行。请解决我的问题